Computing.Net > Forums > Windows XP > Batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch file

Reply to Message Icon

Name: nh
Date: September 21, 2009 at 01:08:21 Pacific
OS: Windows XP
Product: Microsoft Windows xp professional edition
Subcategory: General
Tags: coding, XP, bat, batch
Comment:

Hi Gurus,
I have 1000's of photos named in following format by a Nokia phone camera:

ddmmyyyyXXX.jpg

XXX is a sequential number but varies in length. First photo is 001. However, after 999 it becomes XXXX as required. I assume it goes to XXXXX also but have not found out yet.

The good news is that the first part of the existing filename (ddmmyyyy) is always the same length.

e.g. New Years eve photo's might be
3112200900674.jpg
3112200900675.jpg
0101201000676.jpg (after midnight)

I want to rename them all in American date format so that I can sort & manipulate them in a chronological order using filename alone. I have programs that are unable to sort by 'date modified' etc.

Desired format is:

yyyymmddXXX.jpg

Can this be done?
How?

All the best,
Nigel (Australia)



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: September 21, 2009 at 01:54:28 Pacific
Reply:

:: JPGREN.BAT Usage: jpgren Folder_Name
@echo off & setlocal EnableDelayedExpansion
pushd %*
echo.& echo.  Renaming .jpg files in "%CD%", please wait...
for %%j in (*.jpg) do (
  set _name=%%~nj
  set _date=!_name:~4,4!!_name:~2,2!!_name:~0,2!
  set _name=!_name:~8!
  ren %%j !_date!!_name!.tmp
)
ren *.tmp *.jpg
echo.  DONE
popd
:: End_Of_Batch


0

Response Number 2
Name: nh
Date: September 21, 2009 at 15:26:55 Pacific
Reply:

OK very awesome! I am impressed.

However, my fault, I did not quite think the spec through enough. After I tested your code (thanks again it was a total blast seeing it do exactly what I asked you for!) I realised that the number of digits after the date (i.e. XXX, XXXX, or XXXXX) sets an order of magnitude that then 'dominates' the filename sorting.

Is it possible to make another bat file, or ideally add it to the current one as a "second" pass I think, that takes all characters after the constant 8-digit date and always puts it into a 6-digit XXXXXX format? I say 6-digits as then you could easily deal with an essentially infinite (i.e. 10e6 - 1) number of photos, although, by the way, I am only dealing with a few 1000, maybe into 10,000's eventually.

To truly work the following is required:
e.g.
yyyymmdd012.jpg >> yyyymmdd000012.jpg
yyyymmdd937.jpg >> yyyymmdd000937.jpg
yyyymmdd2345.jpg >> yyyymmdd002345.jpg

Currently, after I ran your code, then I sorted, ascending, by filename, I see that 20090728 ends up sorted "after" the more recent dates because it has the larger XXXX and hence magnitude.

i.e.
20090825010 (XXX= 010) (2nd oldest)
20090902011 (XXX= 011) (3rd oldest)
20090922012 (XXX =012) (newest date)
200907281000 (XXXX=1000) (oldest date, should be at top)

In proposed scheme it would be correctly sorted before the more recent date in true chronological order.

20090728001000 (XXXXXX=001000)
20090825000010 (XXXXXX=000010)
20090902000011 (XXXXXX=000011)
20090922000012 (XXXXXX=000012)

I truly appreciate your time so far and am very exited that this will truly work and be useful to not only me but possibly some of the other billion (guessing) Nokia phone camera users.

All the best,
Nigel (Australia)


0

Response Number 3
Name: IVO
Date: September 22, 2009 at 12:06:58 Pacific
Reply:


Check your Private Message area as I sent you a message with my mail address so you can contact me by e-mail.


0

Response Number 4
Name: IVO
Date: September 23, 2009 at 13:06:22 Pacific
Reply:


Contact me, your script is ready, professional coded, with input checking, on-line help and switches to process date,sequence number or both.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Rename folders via anothe... Macro to count entries


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Batch file

Batch file www.computing.net/answers/windows-xp/batch-file/180885.html

Auto folder Batch file www.computing.net/answers/windows-xp/auto-folder-batch-file/145055.html

simple batch file www.computing.net/answers/windows-xp/simple-batch-file/149160.html