英文:
Copy list of files recursively using Windows CMD
问题
我有一个文本文件中的文件列表。
示例,t.txt
文件的内容:
a.txt
b.jpg
c.bat
我想要一个脚本来从源目录及其子目录中复制文件到特定目标位置。
目前,我在命令提示符(CMD)中使用以下命令:
for /f %I in (t.txt) do copy "C:\ProgramFiles\%I" . /y
这仅从 ProgramFiles
目录复制文件到当前目标位置。
如何修改此命令以允许搜索其子目录?
英文:
I have a list of files in a text file.
Example, content of t.txt
file:
a.txt
b.jpg
c.bat
I want a script to copy files from a source directory, and its subdirectories, to a particular destination.
As of now, I am using the following within the Command Prompt (CMD):
for /f %I in (t.txt) do copy "C:\ProgramFiles\"%I . /y
This copies files only from ProgramFiles
directory to the present destination.
How can I modify this, to allow the search of its subdirectories too?
答案1
得分: 0
你可以通过Windows的xcopy
命令来轻松完成这个任务,类似这样:
@echo off
set "src=H:\JP and Stella\Part 1\Style\Logo\Free dom"
set "dest=C:\Users\starz\Downloads\Selected Photos\"
for /f "usebackq delims=" %%I in ("t.txt") do (
for /r "%src%" %%J in ("*%%I") do (
xcopy /y "%%J" "%dest%"
)
)
在我的代码中,它会从t.txt
中读取文件名,在H:\JP and Stella\Part 1\Style\Logo\Free dom
目录及其子目录中搜索这些文件,并将它们复制到C:\Users\starz\Downloads\Selected Photos\
目录。
英文:
you can easily do that via xcopy
in windows(cmd), something like this :
@echo off
set "src=H:\JP and Stella\Part 1\Style\Logo\Free dom"
set "dest=C:\Users\starz\Downloads\Selected Photos\"
for /f "usebackq delims=" %%I in ("t.txt") do (
for /r "%src%" %%J in ("*%%I") do (
xcopy /y "%%J" "%dest%"
)
)
in my code, it will read the file names from t.txt
, search for them in the H:\JP and Stella\Part 1\Style\Logo\Free dom
directory and its subdirectories, and copy them to the C:\Users\starz\Downloads\Selected Photos\
directory
is it ok ?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论