How can I create a batch script which selects the oldest file in a folder, renames it, moves it to another file and renames it again?


#1

I am very new to programming/coding. I’ll try my best to explain my problem (sry for my english).

Im working on a Windows Server 2012 and I want to create a batch script which selects the oldest file in a folder, renames it, moves it to another folder and renames it again.

Another way to explain it:

I have a folder with 15 files in it
The oldest file is called “orange”
I want the script to rename the “orange” file
Now moving the file to another folder and finally rename it again
I got this so far from somewhere else in here but I dont know if it works or what exactly it means I just saved it so I have at least something to show you guys…

@echo off
cd c:\Test
for /F “delims=” %%a in (‘dir /B /A:-D /O:D /T:W’) do (
move “%%a” C:\Another\Location
goto continue
)

:continue
I think I have to include the following: ren [drive:][path]TargetMask but Im not sure at all… I hope you can understand this. I already tried to look up my problem but just got more confused… Any help is greatly appreciated. Thank you


#2

Were you able to create the script?