0

我有一堆文件夹命名为日期 Ex 20132706, 20132306, 20132205, 20133004.

我想将这些文件夹移动到相应的文件夹中,我可以只写 1000 行,但我想添加通配符。

这就是我目前正在做的事情:

Move \\folder1\20132706  \\folder1\june2013
Move \\folder1\20132306  \\folder1\june2013
Move \\folder1\20132205  \\folder1\May2013
Move \\folder1\20133004  \\folder1\April2013

这就是我想要做的:

Move \\folder1\??????06 \\folder1\june2013
Move \\folder1\??????05 \\folder1\may2013
Move \\folder1\??????04 \\folder1\april2013

但是我没有成功使用通配符。

我究竟做错了什么?

4

1 回答 1

1
@ECHO OFF
SETLOCAL
SET localroot=u:\folder
FOR /f %%i IN (
  'dir /ad /b "%localroot%" ^|findstr /r "^[0-9]*$"'
 ) DO CALL :movedir %%i

GOTO :EOF

:movedir
:: ensure destination is exactly 8 chars long
SET "dest=%1"
SET dest=%dest:~7%
IF NOT DEFINED dest GOTO :EOF 
SET dest=%dest:~1%
IF DEFINED dest GOTO :EOF

SET "dest=%1"
:: convert month to text
SET "month="
SET "dest="&FOR %%i IN (01 january 02 february 03 march etc etc 12 december) DO IF NOT DEFINED dest (
 IF DEFINED month SET dest=%%i%dest:~0,4%
 IF %dest:~-2%==%%i SET month=Y
)

ECHO MOVE %localroot%\%1 %localroot%\%dest%

GOTO :eof

这应该可以完成所需的工作 - 您需要做的就是更改localroot定义,以指示的格式填写月份列表,然后检查删除ECHO以激活MOVE.

遍历目录,只过滤掉那些纯数字(开始和结束之间的任意数量的数字)

检查名称是否正好是 8 长,转换并重新格式化目标名称,然后完成!

于 2013-06-27T02:32:08.597 回答