这完全在Windows XP中使用VBScript。
我有一个包含多个文件的目录。这些文件具有不同的权限集。我需要能够在保留权限的同时将文件复制到新目录。使用下面的脚本,副本工作正常,但新的父文件夹将覆盖权限。
我知道xcopy,但我不确定如何让它在脚本中运行。使用robocopy是一种可能性很小,但如果可能的话应该避免使用。由于网络限制,其他公用事业是不可能的。
非常感谢任何帮助。
Dim CopyFromPath, CopyToPath
Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Const OverwriteExisting = TRUE
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE,"Select folder to copy:",NO_OPTIONS,ssfDRIVES)
if (not objFolder is nothing) then
Set objFolderItem = objFolder.Self
CopyFromPath = objFolderItem.Path
else
Set objShell = nothing
WScript.Quit(0)
end if
Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "Where should the folder be copied to?:", NO_OPTIONS, ssfDRIVES)
if (not objFolder is nothing) then
Set objFolderItem = objFolder.Self
CopyToPath = objFolderItem.Path
else
Set objShell = nothing
WScript.Quit(0)
end if
Set objFolder = nothing
Set objFolderItem = nothing
Set objShell = nothing
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile CopyFromPath & "\*.*", CopyToPath & "\", OverwriteExisting
msgbox "The folder has now been copied to " & CopyToPath
答案 0 :(得分:0)
xcopy对它来说是一个好主意。 <是/> 如何使其在vbscript中工作的示例。
Set oWSHShell = CreateObject("WScript.Shell")
oWSHShell.Exec "xcopy C:\source C:\destination /O /X /H /K /Y"
Set oWSHShell = Nothing