标题: 如何用VBS来复制某文件以及子目录中的文件 ? [打印本页]
作者: smallbear 时间: 2010-2-10 21:56 标题: 如何用VBS来复制某文件以及子目录中的文件 ?
如何用VBS来复制某文件以及子目录中的文件?例如我想把D盘中(包括D盘中所有目录以及子目录)中的PDF文件复制到E盘的123文件夹中应该如何操作?
谢谢。
作者: more 时间: 2010-2-10 23:29
不知道是不是这个意思?- Option Explicit
-
- Dim objFSO, strPath, objFolder, objFile
- strPath = "d:\"
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objFolder = objFSO.getfolder(strPath)
- Call GetAllFolders(objFolder)
- For Each objFile In objFolder.Files
- If objFSO.GetExtensionName(objFile.Name) = "pdf" Then
- objFSO.GetFile(objFile).Copy ("e:\123\)
- End If
- Next
- Set objFSO = Nothing
- Set objFolder = Nothing
-
- Sub GetAllFolders(Folder)
- Dim SubFolder, objFile, objFSO
- Set objFSO = CreateObject("scripting.filesystemobject")
- For Each SubFolder In Folder.SubFolders
- For Each objFile In SubFolder.Files
- If objFSO.GetExtensionName(objFile.name) = "pdf" Then
- objFSO.GetFile(objFile).Copy ("e:\123\")
- End If
- Next
- Call GetAllFolders(SubFolder)
- Next
- Set objFSO = Nothing
- End Sub
复制代码
作者: smallbear 时间: 2010-2-11 22:02
谢谢帮忙,我先试试啊。
作者: smallbear 时间: 2010-2-11 22:25
不行啊,提示有错误。
作者: more 时间: 2010-2-11 23:52
二楼的少了个引号,呵呵...- Option Explicit
-
- Dim objFSO, strPath, objFolder, objFile
- strPath = "d:\"
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objFolder = objFSO.getfolder(strPath)
- Call GetAllFolders(objFolder)
- For Each objFile In objFolder.Files
- If objFSO.GetExtensionName(objFile.Name) = "pdf" Then
- objFSO.GetFile(objFile).Copy ("e:\123\") '这里少了个引号,汗...
- End If
- Next
- Set objFSO = Nothing
- Set objFolder = Nothing
-
- Sub GetAllFolders(Folder)
- Dim SubFolder, objFile, objFSO
- Set objFSO = CreateObject("scripting.filesystemobject")
- For Each SubFolder In Folder.SubFolders
- For Each objFile In SubFolder.Files
- If objFSO.GetExtensionName(objFile.name) = "pdf" Then
- objFSO.GetFile(objFile).Copy ("e:\123\")
- End If
- Next
- Call GetAllFolders(SubFolder)
- Next
- Set objFSO = Nothing
- End Sub
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |