如何使 VBScript 复制文件权限

发布于 2024-12-06 04:36:39 字数 1284 浏览 0 评论 0原文

这都是在 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 

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 = 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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半衬遮猫 2024-12-13 04:36:39

xcopy 是一个好主意。
如何使其在 vbscript 中工作的示例。

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文