create batch file to copy folder contents with dynamic name

对着背影说爱祢 提交于 2020-01-02 08:55:09

问题


I am absolutely brand new to any kind of development but need a batch job to copy a file from one folder to another. The problem is that the source folder is dynamically named. The folder name will contain the current date and a suffix number (eg. "TestRun_20141106_13") - so I will never be able to determine the 'latest' version of the folder before running the batch / copy job.

Can anyone help please? I know this will be easy for someone but as I said, I am a complete noob!!

Thanks in advance. Jamie


回答1:


Yes, I havent been doing .bat for that long either, but i think i can help!

Here is a code for the movement of the file!

Dealing wiwth dynamically named folder...

@echo off 
set /p txtfile=Filename without Path assumes c:\: 
echo.%txtfile% 
copy %txtfile% z:\testing\dealer.txt 
echo Come back to this window when Agent is done with process. The copy file will be deleted. 
@pause 
copy %txtfile% c:\somefolder\namedsuccess\%txtfile% 
del z:\testing\dealer.txt 
exit 

You will have to place your own variables in there my friend!

For moving of the files! Easy part!

move /-y "Folder Path that files are in*(Any specific keyword?)*" "(Dest. folder)"



回答2:


@ECHO OFF
FOR /F "TOKENS=*" %%A IN ('DIR "C:\Example" /s /b /a:d') DO SET CurrentDir=%%A
@ECHO.%CurrentDir%

Replace "C:\Example" with the Path your Folders are in, save it to a File (.bat/.cmd) and execute.

The last step - Echo will return the most bottom foldername.



来源:https://stackoverflow.com/questions/26785140/create-batch-file-to-copy-folder-contents-with-dynamic-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!