我需要将一些特定文件从本地网络复制到我的电脑上。问题是,我无法单独完成所有操作,因为网络包含的数据很容易超过 50 GB,太多了,无法手动筛选。所以我只需要移动特定的文件格式(.mp3、.wav、.mp4)。我该怎么做?我对此很陌生,不知道自己在做什么。
谢谢!
答案1
你只需要两个命令
- 用于
net use
连接共享资源 - 用于
xcopy
复制文件
示例脚本:
net use z: \\some_host\$c secret_password /user:some_domain\some_user
md g:\xc
xcopy z:*.mp3 g:\xc\ /E /C /I /G /H /Z /B
xcopy z:*.wav g:\xc\ /E /C /I /G /H /Z /B
xcopy z:*.mp4 g:\xc\ /E /C /I /G /H /Z /B
其中net use
参数为:
z: - some free drive letter
\\some_host\$c - default windows C:\ share on some_host in your network
/user: - user that have access to this share
secret_password - this user password
其中xcopy
参数为:
z:*.mp3 Source and file mask
g:\xc\ Destination
/E Copies directories and subdirectories, including empty ones.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
/G Allows the copying of encrypted files to destination that does
not support encryption.
/H Copies hidden and system files also.
/Z Copies networked files in restartable mode.
/B Copies the Symbolic Link itself versus the target of the link.
如果您将通配符 ( \\*
) 指定为计算机,则可以使用 psexec 在所有当前域计算机中以反向方式进行复制
psexec \\* -u some_domain\some_user -p secret_password -h -c script.cmd
在哪里
-u Specifies optional user name for login to remote
computer.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.
-h If the target system is Vista or higher, has the process
run with the account's elevated token, if available.
-c Copy the specified program to the remote system for
execution. If you omit this option the application
must be in the system path on the remote system.
例子script.cmd
:
net use z: \\your_host\some_share
xcopy c:*.mp3 z:\ /E /C /I /G /H /Z /B /R /Y
net use z: /delete
您应该使用附加参数:
/R Overwrites read-only files.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.