[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] [已解决]批处理如何把多个jpg全部copy到d盘0000目录下?

本帖最后由 ygqiang 于 2014-11-1 01:17 编辑

xx盘DCIM目录下有不同的子目录,里面有很多*.jpg文件,如何全部copy到d盘yy目录下?
只想找到所有jpg文件,全部复制到目标目录下面。
  1. md "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"
  2. setlocal enabledelayedexpansion
  3. for /f %%i in ('dir /b/s e:\*.jpg') do (copy "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"  /y
  4. del /q "%%~fi")
  5. for /f %%i in ('dir /b/s e:\*.mov') do (copy "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"  /y
  6. del /q "%%~fi")
  7. for /f %%i in ('dir /b/s e:\*.avi') do (copy "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"  /y
  8. del /q "%%~fi")
  9. for /f %%i in ('dir /b/s e:\*.mp4') do (copy "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"  /y
  10. del /q "%%~fi")
  11. for /f %%i in ('dir /b/s e:\*.mts') do (copy "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"  /-y
  12. del /q "%%~fi")
  13. pause
复制代码
以上代码运行正常。
  1. for %%a in (e f g h i j k l m n o p q r s t) do (
  2. if exist "%%a:\DCIM" (md "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"
  3. setlocal enabledelayedexpansion
  4. for /f %%i in ('dir /b/s %%a:\*.jpg') do (copy "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"  /y
  5. del /q "%%~fi")
  6. for /f %%i in ('dir /b/s %%a:\*.mov') do (copy "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"  /y
  7. del /q "%%~fi")
  8. for /f %%i in ('dir /b/s %%a:\*.avi') do (copy "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"  /y
  9. del /q "%%~fi")
  10. for /f %%i in ('dir /b/s %%a:\*.mp4') do (copy "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"  /y
  11. del /q "%%~fi")
  12. for /f %%i in ('dir /b/s %%a:\*.mts') do (copy "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"  /-y
  13. del /q "%%~fi")
  14. )
  15. )
复制代码
更新下:这个代码,修改以后,可以正常运行了。

  1. @echo off
  2. for %%a in (e f g h i j k l m n o p q r s t) do (
  3.     if exist "%%a:\DCIM" (
  4.         md "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"
  5.         for %%b in (jpg mov avi mp4 mts) do (
  6.             for /f %%i in ('dir /b /s /a-d %%a:\*.%%b') do (
  7.                 copy /y "%%~fi" "d:\%date:~0,4%-%date:~5,2%-%date:~8,2%"
  8.                 del /q "%%~fi"
  9.             )
  10.         )
  11.     )
  12. )
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

本帖最后由 ygqiang 于 2014-11-1 01:16 编辑

最终代码如下:
  1. ————————————————————————————————————————————————————————————————
  2. md "d:\%date:~0,4%-%date:~5,2%"
  3. explorer "d:\%date:~0,4%-%date:~5,2%"
  4. for %%a in (e f g h i j k l m n o p q r s t) do (
  5.     if exist "%%a:\DCIM" (
  6.         for %%b in (jpg arw crw cr2 nef rw2 orf raf dng x3f avi mov mp4 mts) do (
  7.             for /f %%i in ('dir /b /s /a-d %%a:\DCIM\*.%%b') do (
  8.                 copy /y "%%~fi" "d:\%date:~0,4%-%date:~5,2%"
  9.                 del /q "%%~fi"
  10.             )
  11.         )
  12.         for %%b in (mp4 mts) do (
  13.             for /f %%i in ('dir /b /s /a-d %%a:\*.%%b') do (
  14.                 copy /y "%%~fi" "d:\%date:~0,4%-%date:~5,2%"
  15.                 del /q "%%~fi"
  16.             )
  17.         )
  18.     )
  19. )
  20. ————————————————————————————————————————————————————————————————
复制代码

TOP

返回列表