3

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

jamieleesis
  • 41
  • 1
  • 3

2 Answers2

2

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)"
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Select your code area, then press `{}` (on top of edit window) to auto-indent by 4 spaces which formats & highlights your code. – Magoo Nov 11 '14 at 09:41
0
@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.

BaBa
  • 337
  • 2
  • 10