Lm th? no ? c ?c m?t tn t?p ng?n t? m?t tn t?p tin di

D?ch tiu ? D?ch tiu ?
ID c?a bi: 175512 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

Trong nh?ng tr?ng h?p nh?t ?nh, n c th? l c?n thi?t ? c ?c tn t?p ng?n tng ng c?a m?t t?p tin c tn t?p di. V d? d?i y s? cho php b?n ch?n m?t t?p tin c tn t?p di v tr? l?i n l ng?n Tn t?p tin b?ng cch s? d?ng ch?c nng API GetShortPathName g?i.

THNG TIN THM

V d? m? sau bao g?m m?t ch?c nng m s? chuy?n ?i t? lu tn t?p tin vo tn t?p ng?n tng ng c?a h? v c?ng bao g?m m?t n gi?n cu?c bi?u t?nh c?a cc ch?c nng s? d?ng.

V d?-by-step

  1. T?o m?t d? n tiu chu?n EXE m?i trong Visual Basic. Form1 ?c t?o ra b?i m?c ?nh.
  2. ?t m?t CommandButton trn Form1.
  3. ?t m?t i?u khi?n h?p tho?i chung v? h?nh th?c.
  4. T? cc Chn tr?nh n, ch?n M-un ? thm m?t m-un m? duy nh?t ? cc d? n.
  5. Thm m? sau y ? Module1:
       Declare Function GetShortPathName Lib "kernel32" _
          Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
          ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    
       Public Function GetShortName(ByVal sLongFileName As String) As String
           Dim lRetVal As Long, sShortPathName As String, iLen As Integer
           'Set up buffer area for API function call return
           sShortPathName = Space(255)
           iLen = Len(sShortPathName)
    
           'Call the function
           lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
           'Strip away unwanted characters.
           GetShortName = Left(sShortPathName, lRetVal)
       End Function
    					
  6. Thm m? sau y ? Form1:
       Private Sub Command1_Click()
         Dim msg As String
         CommonDialog1.FileName = "*.*"
         CommonDialog1.ShowOpen
         msg = "Long File Name: " & CommonDialog1.filename & vbCrLf
         msg = msg & "Short File Name: " & GetShortName(CommonDialog1.filename)
         MsgBox msg
       End Sub
    					
  7. Ch?y cc d? n b?ng cch b?m phm F5. Nh?p vo nt l?nh ? hi?n th? h?p tho?i ? m?. i?u h?ng m? h?p v t?m th?y m?t t?p tin c m?t tn t?p di. Ch?n t?p v b?m OK.
  8. H?p thng bo s? hi?n th? tn t?p tin di cng v?i ng?n c?a n Tn t?p.

THAM KH?O

? bi?t thm chi ti?t, xin vui l?ng xem cc bi vi?t sau y trong cc C s? ki?n th?c Microsoft:
154822 Lm th? no ? c ?c m?t tn t?p tin di t? m?t tn t?p ng?n

Thu?c tnh

ID c?a bi: 175512 - L?n xem xt sau cng: 19 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Visual Basic 5.0 Control Creation Edition
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 4.0 Standard Edition
  • Microsoft Visual Basic 6.0 Professional Edition
T? kha:
kbdocfix kbhowto kbmt KB175512 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:175512

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com