[英]Move files to folders based on file name
I am new to batch files although have searched thoroughly and found topics with a similar BUT not covering what I need. 我是批处理文件的新手,尽管已进行了彻底搜索并找到了与我所需要的内容类似的主题,但是却没有涉及。
I work with lots of documents (.pdf, .doc, .xls ) saved in C:\\Tempfolder. 我处理保存在C:\\ Tempfolder中的许多文档(.pdf,.doc,.xls)。 once I am done editing I save the file name with 9 digit numbers eg( 305123123.pdf or 306123123.pdf or .doc )
完成编辑后,我用9位数字保存文件名,例如(305123123.pdf或306123123.pdf或.doc)
I am looking to create a batch file which will automate move the files that start with 305 to C:\\Users\\Omer\\Documents\\aaCompany or if 306 to C:\\Users\\Omer\\Documents\\bbCompany 我正在寻找一个批处理文件,它将以305开头的文件自动移动到C:\\ Users \\ Omer \\ Documents \\ aaCompany,或者将306移到C:\\ Users \\ Omer \\ Documents \\ bbCompany
I can have upwards of 200 files in the folder at any one time when I decide to process. 当我决定进行处理时,我随时可以在该文件夹中存储多达200个文件。
I am also curious if the batch file can monitor C:\\Tempfolder and move the files 305 or 306 without executing it 我也很好奇批处理文件是否可以监视C:\\ Tempfolder并在不执行的情况下将文件305或306移动
Help on this is greatly appreciated. 非常感谢您对此的帮助。
I hope I have provided sufficient information to see if this is feasible. 我希望我提供了足够的信息以查看这是否可行。
You can make something like this : 你可以做这样的事情:
@Echo off &cls
::The Input Folder
set $Dossier="C:\Tempfolder"
::The Output Folders
set $Out305="C:\Users\Omer\Documents\aaCompany"
set $Out306="C:\Users\Omer\Documents\bbCompany"
::The extensions to wait
set "$Format=*.pdf,*.xls,*.doc"
setlocal enabledelayedexpansion
:Boucle
cls&echo Waiting for file ...
for /f %%a in ('dir /b/a-d %$Dossier%\%$Format% 2^>nul') do (
set "$Fichier=%%a"
echo Treating -^> %%a
if "!$Fichier:~0,3!"=="305" move "%%~nxa" %$Out305%
if "!$Fichier:~0,3!"=="306" move "%%~nxa" %$Out306%
)
::Waiting ~5 secondes
ping localhost -n 6 >nul
::Return to the loop
goto:Boucle
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.