Computing.Net > Forums > Disk Operating System > DOS Scripting / Rename files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DOS Scripting / Rename files

Reply to Message Icon

Name: John
Date: November 27, 2002 at 07:49:39 Pacific
OS: Win 2K
CPU/Ram: P3
Comment:

How could I rename all my digital pictures with the creation date and time concatinated together, instead of the usual counter?



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: November 27, 2002 at 09:59:33 Pacific
Reply:

You want to rename all files from a certain folder to their creation date and time, instead of their original names, is that it?

That's possible, I can make a simple script for that. I just need you to say which format would you like. Example:

MMDDYY-HHMM (military time)
ex: 122702-1558

DDMMYYYY-HHMM(AM/PM)
ex: 27112002-0358AM

Or whatever you want.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 2
Name: John
Date: December 1, 2002 at 19:16:46 Pacific
Reply:

Hi secret_doom:

I am glad to hear that my request is possible. You understand my request perfectly. I would like to change the name of all my pictures in a particular directory to the date and time in the format (YYMMDD-HHMM).

John
jls667@yahoo.com


0

Response Number 3
Name: Secret_Doom
Date: December 1, 2002 at 19:57:09 Pacific
Reply:

Ok, here we go! The following batch script will rename the files from the current directory to their creation date and time, with the format YYMMDD-HHMM.extention (the extention will be mantained).

===== BATCH SCRIPT BEGIN =====
@echo off

if "%OS%"=="Windows_NT" goto OSOK
echo This program must be run in a NT system.
goto eof

:OSOK
if "%1"=="GoTo" goto %2
%comspec% /v /c %0 GoTo start
goto eof

:start
for %%? in (*.*) do (
    for /F "tokens=1-6 delims=/-: " %%A in ("%%~t?") do (
        set MM=%%A
        set DD=%%B

        set YYYY=%%C
        set HH=%%D
        set MI=%%E
        set AP=%%F
        if "!AP!"=="PM" set /A HH += 12
        set YY=!YYYY:~-2!
        REN %%~s? !YY!!MM!!DD!-!HH!!MI!%%~x?
    )
)

:eof
===== BATCH SCRIPT END =====

That's it! If month and day appear swapped, you should swap the green lines. You might want to change the red line (which tells the file format). In this case, mantain the blue part of the line.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

_____________________________________________________


0

Response Number 4
Name: Secret_Doom
Date: December 1, 2002 at 19:59:42 Pacific
Reply:

By the way, be careful, the process is unreversible (the original filenames are not stored for eventual reversing).

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 5
Name: John
Date: December 2, 2002 at 18:29:11 Pacific
Reply:

Why would I get a syntax error?

John


0

Related Posts

See More



Response Number 6
Name: Secret_Doom
Date: December 18, 2002 at 20:45:55 Pacific
Reply:

I have no idea why you could get a sintax error. I've tested that script not only on WinXP, but also in Win95Cmd.EXE, which is somekind of Win2000's command interpreter emulator.

Try locating the sintax error: you can run the batch script line-by-line by making the following change on the script:

:OSOK
if "%1"=="GoTo" goto %2
%comspec% /v /c %0 GoTo start
goto eof

To this:

:OSOK
if "%1"=="GoTo" goto %2
%comspec% /v /Y /c %0 GoTo start
goto eof

Contact me if you locate the sintax error.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 7
Name: Secret_Doom
Date: December 18, 2002 at 21:24:00 Pacific
Reply:

Ooops, forget what I said on my last post about executing the script line-by-line - that /Y thing doesn't work on Win2000.

I still don't know why you get a sintax error, but I found out other things: though that script works on WinXP, it doesn't work as intended on Win2000. I've understimated the differences between these two systems, which are a few but could make a huge difference in some cases.

I've developed another script, which should work on Windows 2000. I can't assure you won't go through the same sintax error, but it's possible that you don't, since the script is different (but I think you will...). Anyway, I'll still post the script for further reference.

===== BATCH SCRIPT BEGIN =====
@echo off
if "%1"=="GoTo" goto %2

ver |FIND "Microsoft Windows 2000" > nul
if not errorlevel=1 goto OSOK
echo This program must be run in Microsoft Windows 2000.
goto eof

:OSOK
%comspec% /v:on /c %0 GoTo start
goto eof

:start
for %%? in (*.*) do (
    for /F "tokens=1-6 delims=/-: " %%A in ("%%~t?") do (
        set MM=%%A
        set DD=%%B
        set YY=%%C
        set HH=%%D
        set MI=%%E
        if "!MI:~-1!"=="p" set /A HH += 12
        set MI=!MI:~0,-1!

        :: To activate the script, remove "echo.{demo}" from next line
        echo.{demo}REN %%~s? !YY!!MM!!DD!-!HH!!MI!%%~x?

    )
)

:eof
===== BATCH SCRIPT END =====

The script is de-activated. If you run it like that, it will display the actions that it would take if active. Analise the output, and if those are the desired actions, activate the script (read commented lines for doing so).

That script was tested on Win95Cmd.exe, some sort of Windows 2000's command interpreter emulator. It should work on Windows 2000.

I'm sorry about all the trouble.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

__________________________________________________________


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: DOS Scripting / Rename files

Rename files in DOS - How? www.computing.net/answers/dos/rename-files-in-dos-how/8486.html

Renaming files with a batch script www.computing.net/answers/dos/renaming-files-with-a-batch-script/13970.html

How Do I Rename Files By Date www.computing.net/answers/dos/how-do-i-rename-files-by-date/6312.html