Find newest file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mossbs
Posts: 3
Joined: 13 Aug 2010 02:11

Find newest file

#1 Post by mossbs » 13 Aug 2010 02:25

Hi guys,

Relatively new to batch files so bear with me....

Need to write one that shall find the newest file in 4 different folders....
\\s90\Downloads\PART WKLY1\
\\s90\Downloads\PART WKLY2\
\\s90\Downloads\PART WKLY3\
\\s90\Downloads\PART WKLY4\

the files that come into here have no extension, i then need to rename the file to have a .zip extension. and then move all four files to one single folder...
\\s60\PART WKLY\

any help greatly appreciated!

Cheers,
Dan

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Find newest file

#2 Post by aGerman » 13 Aug 2010 03:59

Probably something like that

Code: Select all

@echo off &setlocal

for /f "delims=" %%a in ('dir /a-d /b /o-d "\\s90\Downloads\PART WKLY1"') do (set "name=%%a" &goto :exitFor1)
:exitFor1
move "\\s90\Downloads\PART WKLY1\%name%" "\\s60\PART WKLY\%name%.zip"

for /f "delims=" %%a in ('dir /a-d /b /o-d "\\s90\Downloads\PART WKLY2"') do (set "name=%%a" &goto :exitFor2)
:exitFor2
move "\\s90\Downloads\PART WKLY2\%name%" "\\s60\PART WKLY\%name%.zip"

for /f "delims=" %%a in ('dir /a-d /b /o-d "\\s90\Downloads\PART WKLY3"') do (set "name=%%a" &goto :exitFor3)
:exitFor3
move "\\s90\Downloads\PART WKLY3\%name%" "\\s60\PART WKLY\%name%.zip"

for /f "delims=" %%a in ('dir /a-d /b /o-d "\\s90\Downloads\PART WKLY4"') do (set "name=%%a" &goto :exitFor4)
:exitFor4
move "\\s90\Downloads\PART WKLY4\%name%" "\\s60\PART WKLY\%name%.zip"



Regards
aGerman

mossbs
Posts: 3
Joined: 13 Aug 2010 02:11

Re: Find newest file

#3 Post by mossbs » 13 Aug 2010 04:18

Thanks for the reply - doing what i asked for.... one small thing... it seems to be working off of the 'date modified' date.... is there any way to get it to work off of the 'date created' instead?

Cheers,
Dan.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Find newest file

#4 Post by aGerman » 13 Aug 2010 04:58

Try to start all FOR loops this way:
for /f "delims=" %%a in ('dir /a-d /b /o-d /tc "\\s90...

Regards
aGerman

mossbs
Posts: 3
Joined: 13 Aug 2010 02:11

Re: Find newest file

#5 Post by mossbs » 13 Aug 2010 08:33

Superb - thanks for your help!

Post Reply