每个批处理将每个特定文件从其目录复制到自己的子目录

时间:2012-11-05 19:05:57

标签: batch-file

我有一个目录结构

C:folder\
        \davis\Myfiles\saved
        \brown\Myfiles\saved
        \smith\Myfiles\saved
        \jones\Myfiles\saved

我想要实现的是这个

for each directory called 'Myfiles'
   IF NOT Exists 'Myfiles\*doc.rtf'
      copy files caled 'Myfiles\*doc.txt' to the subdirectory 'Myfiles\saved'
      move files called 'Myfiles\*doc.txt' to 'somewhereElse'

但是如何使用批处理

1 个答案:

答案 0 :(得分:1)

阅读HELP FOR并试用可能有助于您入门的代码......

for /r /d %%a in (*) do (
 if /i %%~na==myfiles (
    pushd %%a
    for %%b in (*doc.txt) do (
     if not exist %%~nb.rtf (
       echo copy %%b saved
       echo move %%b \somehwereelse
     )
    )
    popd
  )
)