Computing.Net > Forums > Programming > Automated batch-file renaming

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.

Automated batch-file renaming

Reply to Message Icon

Name: Saeung
Date: September 22, 2005 at 02:00:04 Pacific
OS: XP Pro SP2 / MS Server 20
CPU/Ram: P4 3.0, 1GB RAM
Comment:

While scanning invoices from our scanner to a catalog on the server the file(s) are saved as:

FAKT.PDF
FAKT(1).PDF
FAKT(2).PDF ... and so on ...

My goal is to rename theese files to the real
invoice-numbers.
I can setup the scanner-application to auto-execute a program (such as a .BAT-file)
when it detects an incoming scan.
I need to create a batch-file that automatically renames files as follows:

FAKT.PDF => 112817.PDF
FAKT(1).PDF => 112818.PDF
FAKT(2).PDF => 112819.PDF .. and so on ...

How can I set the "variable" for the batch file to remember where to start next time, or how do I call the filenames in the directy so it will understand at which number it should start it process?

I have tried at least 20 different freewares and sharewares and so far none of theese provide this function.

If this is not possible, is there any alternatives?

Please help me on this one, I really need to figure this out....



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: September 22, 2005 at 07:16:19 Pacific
Reply:

Hi Fredde,

This may help.

It uses a file created in %TEMP%\#\ to keep track of where it is. You need to "initialize" it. So for the example you gave, where you want the next name to be 112817.PDF, you need to do this:

md %TEMP%\#
type nul > %TEMP%\#\112816


::::::::::::seq.bat
@echo off
if %1'==' goto :syntax

:main
set lastNUM=
set nextNUM=
for /f "tokens=*" %%F in ('dir /b/od %TEMP%\#') do set /a lastNUM=%%F
if %lastNUM%'==' echo no counterfile && goto :eof
del %TEMP%\#\%lastNUM%
set /a nextNUM=%lastNUM%+1
type nul > %TEMP%\#\%nextNUM%
ren %1 %nextNUM%.pdf
goto :eof

:syntax
echo you need to call %0 with the file to rename

:eof
::::::::::::::::::::::::::::


If at first you don't succeed, you're about average.

M2


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Automated batch-file renaming

Batch file renaming www.computing.net/answers/programming/batch-file-renaming/18676.html

Batch file renaming www.computing.net/answers/programming/batch-file-renaming/8204.html

Batch file rename and move www.computing.net/answers/programming/batch-file-rename-and-move/14397.html