【问题标题】:Trying to copy a file to certain subfolders using command line尝试使用命令行将文件复制到某些子文件夹
【发布时间】:2020-05-26 13:37:47
【问题描述】:

我正在尝试了解如何使用命令行(旨在创建批处理文件以便我可以自动执行此操作)将单个文件复制到多个子文件夹中,

当前文件夹设置为:

C:\MainFolder:

DestinationFolder1
       Sending
       Receiving
DestinationFolder2
       Sending
       Receiving
DestinationFolder3
       Sending
       Receiving

如何将C:\Example.txt 发送到每个目标文件夹中的Sending 目录?

【问题讨论】:

    标签: batch-file command-line copy subdirectory


    【解决方案1】:

    命令行版本:

    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 /?
    

    【讨论】:

    • 非常感谢!用我的测试文件夹试了一下!将进行一些更改并尝试将其付诸实践!
    猜你喜欢
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 2010-10-30
    • 1970-01-01
    相关资源
    最近更新 更多