我有大量的excel文件,其文件名都以如下所示的时间戳结尾:
examplefile_2018_08_24_110222.xlsx
我想根据时间戳的月份和年份移动所有这些文件,但我希望文件夹名称为上个月。因此对于上面的示例,我想创建一个名为July2018的文件夹并将该文件移到该文件夹中。是否可以使用批处理文件来执行此操作?
我认为这将满足您的需要。我添加了一些注释,因此,如果您不懂代码中的一行,请告诉我。
@ECHO OFF
REM get a list of the files
FOR %%F IN (*.xlsx) DO (
REM GET 2nd, 3rd and 4th parts of file name: examplefile_2018_08_24_110222.xlsx
FOR /F "tokens=2,3,4 delims=_" %%G IN ("%%~F") DO (
REM GET previous month and/or year
FOR /F "delims=" %%J IN ('powershell "(Get-Date %%H/%%I/%%G).AddMonths(-1).ToString('MMMMyyyy')"') DO (
REM make the directory
md "%%J" >nul 2>&1
REM move the file
move "%%~F" "%%J\"
)
)
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句