[SOLVED] file rename to date and time created

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
buffyiscool
Posts: 5
Joined: 22 Dec 2015 00:33

[SOLVED] file rename to date and time created

#1 Post by buffyiscool » 22 Dec 2015 00:47

Hi All.

After quite a bit of searching various sites I am still at a loss regarding this problem.

I have a security camera which records its feed as 30 minute segments using a filename format of
***.***.*.***-00-hhmmss (***.***.*.*** = ip address of camera)

I would like to batch rename the files using the file creation date as follows
dd.mm.yyyy-hhmm

All of the solutions I have come across on the Internet are for either appending the date or time and start off simple but then escalate into code that would probably fill a book.

Any help with this would be really appreciated.

Thanks
Colin
Last edited by buffyiscool on 23 Dec 2015 05:25, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: file rename to date and time created

#2 Post by foxidrive » 22 Dec 2015 04:08

buffyiscool wrote:I have a security camera which records its feed as 30 minute segments using a filename format of
***.***.*.***-00-hhmmss (***.***.*.*** = ip address of camera)

I would like to batch rename the files using the file creation date as follows
dd.mm.yyyy-hhmm


Colin, What OS version are you using?
Do you have restrictions on the tools you want to use?

Run this in the folder and shows us some screen output - the format is important.

Code: Select all

@echo off
for %%a in (*.*) do echo %%~ta
pause

buffyiscool
Posts: 5
Joined: 22 Dec 2015 00:33

Re: file rename to date and time created

#3 Post by buffyiscool » 22 Dec 2015 05:50

Hi foxidrive

Thanks for the reply.

I am using Windows 7 OS. Ideally my request would be just code that I could add to an existing batch file which currently changes the extension from .264 to .mpeg.

I ran the code you provided in one of the folders and also took a screenshot of the folder so you could see the original filename format.

Image

Hope you can see the image above.

Once again thanks.
Colin

Squashman
Expert
Posts: 4479
Joined: 23 Dec 2011 13:59

Re: file rename to date and time created

#4 Post by Squashman » 22 Dec 2015 07:42

You can copy and paste from the CMD prompt. Please do so.

buffyiscool
Posts: 5
Joined: 22 Dec 2015 00:33

Re: file rename to date and time created

#5 Post by buffyiscool » 22 Dec 2015 08:30

This is the output from the previous code posted.

Code: Select all

22/12/2015 00:54
22/12/2015 01:24
22/12/2015 01:54
22/12/2015 02:24
22/12/2015 02:54
22/12/2015 03:24
22/12/2015 03:54
22/12/2015 04:24
22/12/2015 04:54
22/12/2015 05:24
22/12/2015 05:45
21/12/2015 21:54
21/12/2015 22:24
21/12/2015 22:54
21/12/2015 23:24
21/12/2015 23:54
22/12/2015 00:24
22/12/2015 11:37
Press any key to continue . . .

buffyiscool
Posts: 5
Joined: 22 Dec 2015 00:33

Re: file rename to date and time created

#6 Post by buffyiscool » 23 Dec 2015 05:20

Hi All

Just to say thanks for all the help I received on this topic.

I have managed to do what I wanted by creating a small vb.net program.

Thanks again. Merry Christmas and all the best for 2016.

Colin

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: file rename to date and time created

#7 Post by foxidrive » 23 Dec 2015 13:09

buffyiscool wrote:I have managed to do what I wanted by creating a small vb.net program.


Excellent. I was waylaid and forgot to return. Sorry.

Thanks again. Merry Christmas and all the best for 2016.

Colin


All the best to you, also. Cheers.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: file rename to date and time created

#8 Post by foxidrive » 23 Dec 2015 13:13

buffyiscool wrote:This is the output from the previous code posted.

Code: Select all

22/12/2015 00:54
Press any key to continue . . .


This code should rename the files as you've requested. Test it in a folder of copies first.

Code: Select all

@echo off
for %%a in (*-*-*) do for /f "tokens=1-5 delims=/: " %%b in ("%%~ta") do ren "%%a" "%%b.%%c.%%d-%%e%%f"

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: file rename to date and time created

#9 Post by thefeduke » 23 Dec 2015 23:01

foxidrive wrote:

Code: Select all

for %%a in (*-*-*) do for /f "delims=/: " %%b in ("%%~ta") do ren "%%a" "%%b.%%c.%%d-%%e%%f"
Replacing

Code: Select all

"delims=/: "
with

Code: Select all

"tokens=1-5* delims=/: "
should help.
John A.

buffyiscool
Posts: 5
Joined: 22 Dec 2015 00:33

Re: [SOLVED] file rename to date and time created

#10 Post by buffyiscool » 24 Dec 2015 01:56

For those interested here is a screenshot of the vb.net program I created to perform the required task.

Image

If image does not show you can view it here: https://www.dropbox.com/s/6tgnvsx4ez2jr ... e.jpg?dl=0

Once again thanks for all the help.

Colin

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: file rename to date and time created

#11 Post by foxidrive » 24 Dec 2015 02:48

thefeduke wrote:

Code: Select all

"tokens=1-5* delims=/: "
should help.
John A.



Thank you John, it certainly requires the tokens. Colin's task doesn't have extensions so I didn't add code for it - why would you when it's not in the job description. :D

Post Reply