user2490024
user2490024

Reputation: 75

Batch script to move oldest file from one folder to other

I have a number of files in my c:\Test folder. I want to move the oldest modified file (file which was modified first) to another location. I am very new to scripting. Could you help me with this issue?

Upvotes: 3

Views: 3211

Answers (2)

Aacini
Aacini

Reputation: 67216

@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

Upvotes: 2

user1666959
user1666959

Reputation: 1855

If you have cygwin ls -ca gives you a list of files sorted in order of modification time. Take the last one (tail -1) and move it where you want to.

Upvotes: 1

Related Questions