Renaming files, using the date of creation to order them...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mbgf23
Posts: 5
Joined: 28 Dec 2010 06:59

Renaming files, using the date of creation to order them...

#1 Post by mbgf23 » 06 Jan 2011 06:35

Hello there,
Again needing your help and here I do not even know how to start my scrip :S
I have a large number of files (around 2000 in the same folder) with different names and no relation between those names, and I need to rename them like this
In a txt file I have the list of names like this:
-----Names.txt------
file1
file2
file4
fileOne
-----EndOfNames.txt---
(Note that the names are not correlative, so I can have "file1" and after that "file24" or "fileUnique", that is why I need to do it with this list.)
But I also need the script to rename in this way, to order the files by creation date like this, the "oldest" will have the name file1.pdf (I forgot to mention that all of them are pdf files, so the extension will be .pdf), the second created will have the name file2.pdf...and so on.
There is some way to do that? I hope so...
And thanks in advance for your help.
(Sorry for my english and do not hesitate to ask if more clarification is needed.)

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: Renaming files, using the date of creation to order them

#2 Post by ChickenSoup » 06 Jan 2011 11:10

Do they have to come from your names.txt file? or can this be generated on the fly from a DIR command?

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

Re: Renaming files, using the date of creation to order them

#3 Post by aGerman » 06 Jan 2011 11:53

Well it's realy not "best practice" to do this in batch, but doable.
The DIR command is able to sort files by creation time (on NTFS formatted volumes). I agree with ChickenSoup, it's easier to work with DIR on the fly because the names in a textfile don't contain the creation time ...

Regards
aGerman

mbgf23
Posts: 5
Joined: 28 Dec 2010 06:59

Re: Renaming files, using the date of creation to order them

#4 Post by mbgf23 » 07 Jan 2011 08:01

yes, unfortunately the names have to came from the txt file :(
In my scenario i know for sure that the first created has to have the first name in my list and so on...and to rename 2000 files on the fly will be crazy...that is why I am trying to make it in a batch.
Thank you very much aGerman and ChickemSoup for your reply!

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

Re: Renaming files, using the date of creation to order them

#5 Post by aGerman » 07 Jan 2011 14:29

mbgf23 wrote:...and to rename 2000 files on the fly will be crazy...

:?: Arm ... WHY?

mbgf23 wrote:In my scenario i know for sure that the first created has to have the first name in my list and so on...

I don't get it. You have already sorted the files by date in your file?
Well then loop over the file using FOR /F and increment a variable that acts as new file name. Use a temporary folder to move the files in the first step to make sure you will never overwrite an existing file with the same name.

Regards
aGerman

Post Reply