当前位置:编程学习 > VB >>

用filecopy 复制文件的时候路径中有空格怎么处理?

  如题! 忘解答. --------------------编程问答-------------------- debug.Print  asc(" ")
 32 
chr(32)代替空格
我碰到"号时,常用chr(34)解决。 --------------------编程问答-------------------- Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
--------------------编程问答--------------------       SourceFile = Chr(34) & SourceFile & Chr(34)
      DestFile = Chr(34) & DestFile & Chr(34)
      FileCopy SourceFile, DestFile --------------------编程问答-------------------- 用2楼的API函数或得该路径的DOS名称,再复制~ --------------------编程问答-------------------- 好像照样能复制过去 --------------------编程问答-------------------- 带空格可以复制
比如下面这样的

FileCopy "d:\1 1 1\1.txt", "d:\2.txt" --------------------编程问答-------------------- '在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 Sub

Public 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

--------------------编程问答-------------------- 有问题请先GOOGLE,BAIDU
补充:VB ,  基础类
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,