试图找到一种方法将目录中的文件移动到其中包含的子目录中。
例如:
January
| 001.jpg
| 002.jpg
| ...
| 100.jpg
|
\---Photo
February
| 001.jpg
| 002.jpg
| ...
| 100.jpg
|
\---Photo
和
March
,April
等
我一直在手动做,但它可能很耗时。
非常感谢大家。
如果我很了解你,这里有一个例子
folder/
├── file2.txt
├── file.txt
└── subfolder
mv folder/subfolder .
mv folder/* subfolder
mv subfolder folder
结构将是
folder/
└── subfolder
├── file2.txt
└── file.txt
@ECHO OFF
SETLOCAL
rem The following setting for the directory is a name
rem that I use for testing and deliberately includes spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "sourcedir=u:\your files"
REM (
FOR /f "delims=" %%b IN ('dir /b /a-d "%sourcedir%\*" ') DO (
FOR /f "tokens=2delims=/-." %%m IN ("%%~tb") DO (
FOR %%c IN ("01,January" "02,February" "03,March" "04,April" "05,May" "06,June" "07,July"
"08,August" "09,September" "10,October" "11,November" "12,December") DO (
FOR /f "tokens=1,2delims=," %%u IN (%%c) DO IF %%u==%%m (
MD "%sourcedir%\%%v" 2>NUL
IF EXIST "%sourcedir%\%%v\%%b" (
ECHO failed to MOVE %%b
) ELSE (
ECHO MOVE "%sourcedir%\%%b" "%sourcedir%\%%v\"
)
)
)
)
)
GOTO :EOF
在应用于真实数据之前,始终对照测试目录进行验证。
所需的 MOVE 命令仅
ECHO
ed 用于测试目的。 确认命令正确后,将ECHO MOVE
更改为MOVE
以实际移动文件。附加>nul
以抑制报告消息(例如1 file moved
)
您可能需要调整
FOR /f "tokens=2delims=/-."
这对于MY日期格式(dd/mm/yyyy)是正确的,但如果您使用mm/dd/yy,那么您需要tokens=1
.
如果您使用 1 位数的月份,则将例如,
"03,March"
更改为 "3,March"