Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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....

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

![]() |
![]() |
![]() |

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