Wrox Programmer Forums
|
Other Programming Languages If you have a coding issue to discuss about another language that really isn't provided for in any other forum here (not ASP.NET C#, C++, VB, PHP, JavaScript, Python, Java, Perl, Applescript, XML or any of the other forum topics we have), post it here. Enough discussion on a language we don't have covered could prompt a new forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Other Programming Languages section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 21st, 2007, 01:21 AM
Registered User
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Batch rename in MSDOS

My camera is creating files like 01042007011.jpg (DAYMONTHYEARNUMBER.EXT).
I would like to create a batch file that rename them to YEARMONTHDAY_NUMBER.EXT, 20070401_011.jpg in my exemple.

As I don't have delimiters, except for the extension, i don't really know how to split the different elements of the filename. I've tried something like this:

Code:
@echo off

for /F "tokens=*" %%A in ('dir *.jpg *.mp4 /B') do (
 for /F "delims=. tokens=1" %%G in ("%%A") do (
     call :_rename %%G
 )
)

goto :_end

:_rename

set filenumber=%1
set filenumber=%filenumber:~-3%
echo %filenumber%

set year=%1
set year=%year:~+4%
echo %year%

:_end
endlocal

pause
This will return:
011 -> working
2007011 -> how to remove the 011 at the end ?

The tilde with the dash (~-) permits me to return only the last 3 characters of my strings. So its working fine to get the filenumber.
I tried to do it with ~+, but it then remove an amount of characters at the beginning. So it only returns the end of the string in both case. I haven't found a way to have only the day, month and year.

Thanks for your help.
Reply With Quote
  #2 (permalink)  
Old November 27th, 2007, 05:18 AM
Registered User
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

btw if it's not possible to do it in msdos, how can i do it ? =) thanks for your help.

Reply With Quote
  #3 (permalink)  
Old November 27th, 2007, 11:04 AM
Registered User
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

after hours, i finally manage to have my batch working =) i should have rename all my pictures manually one by one would have taken me less time hehe. anyways here's the working batch.

Code:
@echo off

for /F "tokens=*" %%A in ('dir *.jpg /B') do (
 for /F "delims=. tokens=1" %%G in ("%%A") do (
     call :_renamejpg %%G
 )
)
for /F "tokens=*" %%A in ('dir *.mp4 /B') do (
 for /F "delims=. tokens=1" %%G in ("%%A") do (
     call :_renamemp4 %%G
 )
)
goto :_end


:_renamejpg
set filenumber=%1
set filenumber=%filenumber:~-3%
set year=%1
set year=%year:~4,4%
set month=%1
set month=%month:~2,2%
set day=%1
set day=%day:~0,2%
ren %1.jpg %year%%month%%day%_%filenumber%.jpg
goto :eof

:_renamemp4
set filenumber=%1
set filenumber=%filenumber:~-3%
set year=%1
set year=%year:~4,4%
set month=%1
set month=%month:~2,2%
set day=%1
set day=%day:~0,2%
ren %1.mp4 %year%%month%%day%_%filenumber%.mp4
goto :eof

:_end
endlocal
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
LNC Rename dmoffice Access VBA 6 November 16th, 2006 09:42 PM
Telnet -login -MsDos ralvarez31 Other Programming Languages 0 May 11th, 2006 07:37 AM
BATCH scapermoya Other Programming Languages 0 May 1st, 2006 08:47 PM
Rename a column JENKINSACTIVE SQL Server 2000 3 December 16th, 2004 01:11 AM
How to restart in Msdos mode using VB? Mass VB How-To 0 February 7th, 2004 01:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.