[英]How to move all *.pdf files in each subfolder of a specific folder to a monthly created subfolder?
I have been attempting to create a single batch file that will do monthly work for me with files throughout various folders.我一直在尝试创建一个批处理文件,该文件将每月为我处理各个文件夹中的文件。
Currently the folder C:\\test\\WSP\\
has numerous other folders (account names) with PDF's in them.目前,文件夹
C:\\test\\WSP\\
有许多其他文件夹(帐户名),其中包含 PDF。 We need to:我们需要:
MM-YYYY
within C:\\test\\WSP\\{Account Name}\\
C:\\test\\WSP\\{Account Name}\\
创建一个带有MM-YYYY
的文件夹C:\\test\\WSP\\{Account Name}\\08-2015\\
with all new PDF's in there.C:\\test\\WSP\\{Account Name}\\08-2015\\
有所有新的 PDF。C:\\test\\WSP\\{Account Name2}
,C:\\test\\WSP\\{Account Name2}
,08-2015
folder and move all the PDFs into C:\\test\\WSP\\{Account Name2}\\08-2015
so on and so forth.08-2015
文件夹并将所有 PDF 移动到C:\\test\\WSP\\{Account Name2}\\08-2015
等等。 I can do process as needed within each {Account Name}
folder by placing a batch file containing:我可以通过放置包含以下内容的批处理文件在每个
{Account Name}
文件夹中根据需要进行处理:
@ECHO OFF
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
set MONTH="%month%"
set YEAR ="%year%""
md %YEAR%\%MONTH%
MOVE *.pdf %YEAR%\%MONTH%\
And running every month in each folder, however, there are over 200 folders here.并且每个月都在每个文件夹中运行,但是,这里有 200 多个文件夹。
Is there anyway to comb through each folder, create the directory and move the PDF's into the new folder, then move onto the next directory?无论如何都要梳理每个文件夹,创建目录并将PDF移动到新文件夹中,然后移动到下一个目录?
Here is a commented batch code for this task:这是此任务的注释批处理代码:
@echo off
rem Get month and year from environment variable DATE. The
rem date format depends on region and language settings for
rem the current user. The code below expects the date in
rem format DD.MM.YYYY or DD/MM/YYYY without or with weekday
rem at beginning which is the reason why referencing the
rem characters to copy from date string is done from end of
rem the string instead of beginning. Run in a command prompt
rem window echo %DATE% to see the date format of your user
rem account.
set "MonthFolder=%DATE:~-7,2%-%DATE:~-4%"
rem Use command FOR to process each non hidden and non
rem system subdirectory of specified parent directory. The
rem loop variable D holds the name of the found subdirectory
rem with complete path.
rem If the subdirectory contains 1 or more files with the
rem file extension PDF, a subdirectory with month any year
rem is created in current subdirectory in case of not already
rem existing and all PDF files are moved into this monthly
rem created subdirectory.
for /D %%D in ("C:\test\WSP\*") do (
if exist "%%D\*.pdf" (
if not exist "%%D\%MonthFolder%\*" md "%%D\%MonthFolder%"
move /Y "%%D\*.pdf" "%%D\%MonthFolder%\" >nul
)
)
set "MonthFolder="
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.要了解使用的命令及其工作原理,请打开命令提示符窗口,在那里执行以下命令,并仔细阅读为每个命令显示的所有帮助页面。
echo /?
for /?
if /?
md /?
move /?
rem /?
set /?
And see also the Microsoft article about Using command redirection operators for an explanation of >nul
which redirects the information output by command MOVE about moved files to device NUL to suppress this information.另请参阅有关使用命令重定向运算符的 Microsoft 文章,以了解
>nul
的说明,该文章将命令MOVE输出的有关已移动文件的信息重定向到设备NUL以抑制此信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.