本站动态:
copydir.bat: 拷贝目录及各级子目录下的文件到一个目录的工具
作者:shosh 日期:2010-03-14
背景:工作中,UI工程师提供图片资源是分目录放置的,可是提交给CM的时候却需要在一个目录下的,如果手动拷贝非常麻烦,而如果直接用COPY 或 XCOPY命令把文件从A目录拷贝到B目录,B目录还是会维持A目录的目录结构。昨天晚上手动写了一根批处理工具,正是用来解决该问题的。具体用法代码中也有,这里不赘述。
copydir.bat代码如下:
- :: Auther: Shosh
- :: Site: http://www.wscxy.com
- :: Date: 2010.03.13
- :: This bat copies all the files under a directory and all levels of subdirectories to another folder(no subfolder)
- @ECHO OFF
- SET DefSrcRootDir=.
- SET DefDestDir=.
- :FunBegin
- SET bConfirm=NO
- IF "%1" == "/?" GOTO FunUsage
- SET bHaveOption=FALSE
- IF "%1" == "/c" SET bHaveOption=TRUE
- IF "%1" == "/C" SET bHaveOption=TRUE
- IF "%1" == "-c" SET bHaveOption=TRUE
- IF "%1" == "-C" SET bHaveOption=TRUE
- IF bHaveOption == TRUE (
- SET bConfirm=YES
- IF "%2" == "" (
- SET srcRootDir=%DefSrcRootDir%
- SET destDir=%DefDestDir%
- ) ELSE (
- IF NOT "%4" == "" GOTO FunErrorUsing
- SET srcRootDir=%2
- SET destDir=%3
- )
- ) ELSE (
- SET bConfirm=NO
- IF "%1" == "" (
- SET srcRootDir=%DefSrcRootDir%
- SET destDir=%DefDestDir%
- ) ELSE (
- IF NOT "%3" == "" GOTO FunErrorUsing
- SET srcRootDir=%1
- SET destDir=%2
- )
- )
- IF "%destDir%" == "" GOTO FunErrorUsing
- ::confirm settings
- ECHO ================================================================
- ECHO Source Root Dir: %srcRootDir%
- ECHO Dest Dir: %destDir%
- ECHO Overwrite Confirm: %bConfirm%
- ECHO ================================================================
- SET /P choice=Start executing? [Y/N]
- if NOT %choice% == Y (
- if NOT %choice% == y GOTO FunCancel
- )
- ::check input directories settings
- IF NOT EXIST %srcRootDir% ECHO [%srcRootDir%] not found!!!
- IF NOT EXIST %destDir% ECHO [%destDir%] not found, we will create it.
- ::check source root dir before starting coping
- IF NOT EXIST %srcRootDir% GOTO FunPause
- IF %bConfirm% == YES (
- :: confirm overwriting
- FOR /R %srcRootDir% %%i IN (.) DO XCOPY "%%i" "%destDir%" /-Y /V /F /I /K
- ) ELSE (
- :: no confirm
- FOR /R %srcRootDir% %%i IN (.) DO XCOPY "%%i" "%destDir%" /Y /V /F /I /K
- )
- ECHO ================================================================
- ECHO Finish!!!
- ECHO Thank you for using copydir.bat written by Shosh!!!
- ECHO Welcome to visit my website http://www.wscxy.com
- GOTO FunPause
- :FunErrorUsing
- ECHO !!! Error using copydir.bat !!!
- GOTO FunUsage
- :FunUsage
- ECHO USAGE: copydir [/C] [source root dir] [dest dir]
- ECHO [/C] Confirm if a file needs overwriting. if not set, it will overwrite without confirm.
- ECHO If set both src root dir and dest dir to ., that means all the files in all levels of subfolders will be copied to the current folder.
- goto FunPause
- :FunCancel
- ECHO You've canceled executing.
- GOTO FunPause
- :FunPause
- ECHO ================================================================
- SET /P a=Press ENTER key to continue...
评论: 0 | 引用: 0 | 查看次数: 442
发表评论
上一篇
下一篇

文章来自:
Tags:
相关日志:






