vbscript - 有没有办法使用 vbs 将驱动器的每个文件和文件夹移动到驱动器本身的文件夹中
问题描述
我需要一个 VBS 中的程序(我也可以使用批处理,但 VBS 会更好),它将我的 USB 驱动器的所有文件和文件夹移动到 USB 中的一个文件夹中。例如:如果在我的 USB 驱动器中有这些目录:
E:\folder1\file.txt
E:\folder2\foder3\file3.txt
E:\file.txt
运行程序后会有以下路径:
E:\newfolder\folder1\file.txt
E:\newfolder\folder2\foder3\file3.txt
E:\newfolder\file.txt
我不知道这是否可能。我已经使用 for 循环制作了一个程序,但它仅适用于文件而不适用于文件夹:
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("E:/")
Sub ShowSubFolders(Folder)
set fs = CreateObject("Scripting.FileSystemObject")
For Each Subfolder in Folder.SubFolders
fs.movefolder Subfolder.Path , "E:\newfolder\"
next
End Sub
With CreateObject("Scripting.FileSystemObject")
.MoveFile "E:\*.*", "E:\newfolder\"
End With
*在此代码中,新文件夹已经存在。
解决方案
Dim sSourcePath
Dim sDestinationPath
Dim objFSO
Dim objSourceFolder
Dim objDestinationFolder
Dim objFolder
' Define paths
sSourcePath = "E:\"
sDestinationPath = "E:\newfolder\"
' Get source and destination folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSourceFolder = objFSO.GetFolder(sSourcePath)
Set objDestinationFolder = objFSO.GetFolder(sDestinationPath)
For Each objFolder In objSourceFolder.Subfolders
If objFolder Is objDestinationFolder Then
' Don't move destination folder
Else
' Move folder to destination folder
objFolder.Move sDestinationPath
End If
Next
推荐阅读
- c++ - 将数组列表作为参数传递给 pthread_create
- python - /website/login/:login() 的 TypeError 采用 1 个位置参数,但给出了 2 个
- sql - 将字符串连接到游标中的临时表中
- c# - 在跨平台 xamarin 项目中编写特定于平台的代码
- python - 数组列表中的输入没有完全反转,使用 FOR 循环时它只过滤两个
- python - 通过多个参数分隔 read_csv
- android - Cordova 和 Galaxy 之间是否存在已知的兼容性问题?
- python - 对不同的输入/输出python使用单个变量
- javascript - 只有在单击第一个按钮时才能单击第二个按钮
- mysql - 将mysql数据从旧的xampp复制到新的