我需要用各种类型的文件填充一堆文件夹。
目标文件夹结构如下
YEAR > COMMITTEE_NAME YEAR > YEAR MONTH COMMITTEE_NAME
EX: 2015 > ADP 2015 > 2015 January ADP
要移动的文件由委员会(MOM,ADP等)放在文件夹中。我必须先按年组织,然后按委员会组织,然后按月组织。
每个文件夹包含由日期和委员会命名的各种类型的文件(例如:2015年1月22日ADP会议的Word文档将为“012215ADP.doc”)。
我想以某种方式自动填充这些文件夹,因为有数百个甚至数千个文件要移动。
我唯一的编程经验是在MATLAB中,我精通,但由于公司规则不允许使用。
我知道如何执行和修改.bat文件,但不知道如何制作它们。
答案 0 :(得分:0)
@echo off
setlocal EnableDelayedExpansion
set "destination=C:\path\that\contain\destination\folders"
rem Change current folder to the one that contain the MOM, ADP, etc. folders
cd "C:\path\to\committees\folder"
rem Create the array of month names (i.e. month[01]=January, etc.)
set i=100
for %%a in (January February March April May June July August September October November December) do (
set /A i+=1
set "month[!i:~1!]=%%a"
)
rem Process all committee folders
for /D %%d in (*) do (
rem Process all files in this folder
cd "%%d"
for %%f in (*.*) do (
rem Format of file name is: "MMddYYCOM.ext"
set "filename=%%~Nf"
set "MM=!filename:~0,2!"
set "YY=!filename:~4,2!"
set "COM=!filename:~6,3!"
rem Move this file to the proper destination folder
for %%m in (!MM!) do set "dest="%destination%\20!YY!\!COM! 20!YY!\20!YY! !month[%%m]! !COM!"
if not exist "!dest!" md "!dest!"
move "%%f" "!dest!"
)
rem Go back to parent folder and pass to next committee folder
cd ..
)