尝试使用命令行将文件复制到某些子文件夹
Trying to copy a file to certain subfolders using command line
我正在尝试了解如何使用命令行(旨在创建一个批处理文件以便我可以自动执行此操作)将单个文件复制到多个子文件夹中,
当前文件夹设置为:
C:\MainFolder:
DestinationFolder1
Sending
Receiving
DestinationFolder2
Sending
Receiving
DestinationFolder3
Sending
Receiving
如何将 C:\Example.txt
发送到每个目标文件夹中的 Sending
目录?
命令行版本:
for /f "delims=" %i in ('dir /b /s /ad C:\Mainfolder ^| findstr /i "Sending"') do copy "C:\Example.txt" "%~i" /Y
批处理文件版本(唯一不同的是双%
:
for /f "delims=" %%i in ('dir /b /s /ad C:\Mainfolder ^| findstr /i "Sending"') do copy "C:\Example.txt" "%%~i" /Y
它只是在 C:\Mainfolder
内的每个文件夹上运行一个具有搜索功能的 dir
命令。使用 findstr
它只会获取包含 Sending
的文件夹,然后将文件复制到其中。
有关上述命令的更多帮助,请打开 cmd
并键入:
for /?
dir /?
findstr /?
我正在尝试了解如何使用命令行(旨在创建一个批处理文件以便我可以自动执行此操作)将单个文件复制到多个子文件夹中,
当前文件夹设置为:
C:\MainFolder:
DestinationFolder1
Sending
Receiving
DestinationFolder2
Sending
Receiving
DestinationFolder3
Sending
Receiving
如何将 C:\Example.txt
发送到每个目标文件夹中的 Sending
目录?
命令行版本:
for /f "delims=" %i in ('dir /b /s /ad C:\Mainfolder ^| findstr /i "Sending"') do copy "C:\Example.txt" "%~i" /Y
批处理文件版本(唯一不同的是双%
:
for /f "delims=" %%i in ('dir /b /s /ad C:\Mainfolder ^| findstr /i "Sending"') do copy "C:\Example.txt" "%%~i" /Y
它只是在 C:\Mainfolder
内的每个文件夹上运行一个具有搜索功能的 dir
命令。使用 findstr
它只会获取包含 Sending
的文件夹,然后将文件复制到其中。
有关上述命令的更多帮助,请打开 cmd
并键入:
for /?
dir /?
findstr /?