Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
'在VB之下直接使用 Private Sub Command1_Click() FileCopy "C:\Program Files\testa b\cmd.txt", "c:\cmd.txt" End Sub'******************************** 'shell(DOS命令)时要将长文件名改为短文件名 Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long Private Sub Command1_Click() FileCopy Getshortname("C:\Program Files\testa b") & "\cmd.txt", "c:\cmd.txt" End SubPublic Function Getshortname(ByVal sLongFileName As String) As String Dim lRetVal&, sShortPathName$, iLen% sShortPathName = Space(255) iLen = Len(sShortPathName) lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen) Getshortname = Left(sShortPathName, lRetVal) jj = InStr(Getshortname, Chr(0)) If jj > 0 Then Getshortname = Mid(Getshortname, 1, jj - 1) End Function
32
chr(32)代替空格
我碰到"号时,常用chr(34)解决。
DestFile = Chr(34) & DestFile & Chr(34)
FileCopy SourceFile, DestFile
比如下面这样的FileCopy "d:\1 1 1\1.txt", "d:\2.txt"
Private Sub Command1_Click()
FileCopy "C:\Program Files\testa b\cmd.txt", "c:\cmd.txt"
End Sub'********************************
'shell(DOS命令)时要将长文件名改为短文件名
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Sub Command1_Click()
FileCopy Getshortname("C:\Program Files\testa b") & "\cmd.txt", "c:\cmd.txt"
End SubPublic Function Getshortname(ByVal sLongFileName As String) As String
Dim lRetVal&, sShortPathName$, iLen%
sShortPathName = Space(255)
iLen = Len(sShortPathName)
lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
Getshortname = Left(sShortPathName, lRetVal)
jj = InStr(Getshortname, Chr(0))
If jj > 0 Then Getshortname = Mid(Getshortname, 1, jj - 1)
End Function