【问题标题】:Batch file to copy files based on file name to corresponding folder批处理文件根据文件名将文件复制到相应的文件夹
【发布时间】:2013-11-23 14:55:58
【问题描述】:

尝试创建一个批处理文件,根据描述将文件从一个文件夹复制到另一个文件夹。例如,如果文件名有六位,我希望它读取前三位并将其放在某个文件夹中,如果文件名只有五位,那么我希望它读取前两位并将该文件复制到不同的文件夹。

文件 704000.txt 进入文件夹 T704

文件 70400.txt 进入文件夹 T70

【问题讨论】:

    标签: batch-file windows-7 copy


    【解决方案1】:

    试试这个:

    @echo on & setlocal enabledelayedexpansion
    goto start
    
    the file structure should look simalar to this:
    
    C:.
    |   file.bat
    |   
    +---a
    |       11111.txt
    |       111111.txt
    |       1111111.txt
    |       22222.txt
    |       222222.txt
    |       33333.txt
    |       333333.txt
    |       44444.txt
    |       444444.txt
    |       55555.txt
    |       555555.txt
    |       66666.txt
    |       666666.txt
    |       77777.txt
    |       777777.txt
    |       88888.txt
    |       888888.txt
    |       99999.txt
    |       999999.txt
    |       
    +---T11
    +---T111
    +---T22
    +---T222
    +---T33
    +---T333
    +---T44
    +---T444
    +---T55
    +---T555
    +---T66
    +---T666
    +---T77
    +---T777
    +---T88
    +---T888
    +---T99
    \---T999
    
    with this being file.bat
    
    :start
    set dir=a
    
    for /f "tokens=*" %%i in ('dir %dir% /s /b') do (
       set filename=%%~ni
       set file=%%i
       if "!filename:~6!" EQU "" (if "!filename:~5!" NEQ "" ( move /Y "%%~i" "T!filename:~0,3!") else if "!filename:~4!" NEQ "" ( move /Y "%%~i" "T!filename:~0,2!"))
    )
    

    【讨论】:

      猜你喜欢
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多