Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > Other Programming Languages
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 21st, 2007, 01:21 AM
Registered User
 
Join Date: Nov 2007
Location: , , .
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
Location: , , .
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
Location: , , .
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
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:05 PM.


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