0
Dim WshNetwork,objNetwork, WshShell, objFSO, objItem
Set objNetwork = CreateObject("Wscript.Network")
Set WshNetwork = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = CreateObject("WScript.Shell")
If not objFSO.FolderExists("C:\Backups") Then
objFSO.CreateFolder "C:\Backups"
Else
End If
If not objFSO.FolderExists("C:\Backups\" & strUserName) Then
objFSO.CreateFolder ("C:\Backups\" & strUserName)
Else
End If
Set FSO = CreateObject("Scripting.FileSystemObject")
strUserName = objNetwork.UserName
Set oMainFolder = FSO.GetFolder("C:\Users\" & strUserName &"\Documents\")
For Each oFolder In oMainFolder.SubFolders
On Error Resume Next
If oFolder.Name <> "My Music" and oFolder.Name <> "My Pictures" and oFolder.Name <> "My Videos" Then
FSO.CopyFolder ("C:\Users\" & strUserName &"\Documents\") & oFolder.Name, ("C:\Backups\" & strUserName) & oFolder.Name, True
FSO.CopyFile ("C:\Users\" & strUserName &"\Documents\*.*"), ("C:\Backups\" & strUserName), True
End If
Next
如果不是objFSO.FolderExists(「C:\ Backups \」&strUserName&「\」)似乎沒有改變我的問題。 – Namemybullets
@Namemybullets - 請反思「初始化」的含義,並記住VBScript語句按順序執行。 –
-_- Doh,lol。謝謝!我用你的提示修復了它。所以我將strUserName上移到了將源文件夾分隔成兩個的變量區域。文件進入用戶名,文件夾進入用戶名+源。爲了解決這個問題,我回去並在Copy.Folder中的目標文件夾路徑後添加「\」。非常感激!再次感謝你:D – Namemybullets