开发者

How to make VBScript copy permissions along with files

This is all in Windows XP utilizing VBScript.

I have a directory with several files inside. The files have varying permissions set. I need to be able to copy the files to a new directory while retaining the permissions. Using the script below the copy works fine but the permissions are overwritten by the new parent folder.

I am aware of xcopy but I am unsure how to make it work within the script. Using robocopy is a slight possibility but should be avoided if at all possible. Other utilities are out of the question due to network contraints.

Any help is greatly appreciated.

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 = objFo开发者_开发技巧lderItem.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 


xcopy is a good idea for it.
An example to how make it work within vbscript.

Set oWSHShell = CreateObject("WScript.Shell")
oWSHShell.Exec "xcopy C:\source C:\destination /O /X /H /K /Y"
Set oWSHShell = Nothing
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜