Jump to content

Batch File Renamer


phillyman2004

Recommended Posts

Just got a new scanner........and of course its got crappy software ........i need a small batchfile that just does the following

==================

Asks Which Prefix would you like to use?

(user enters book)

Which Page does This collection start at?

(User picks 2)

File then proceeds to rename each file in that directory following the directions from the user

book 002

book 004

book 006

.

.

book 116

====================

I am having this problem because my scanner only scans 1 side at a time .....and wont skip every other number......So i am hoping that one of you batch file guru's can write me a small little file that i can run on the first batch of scans for odd numbered scans ......then on the second batch for the even scans .....then i can put them together in a folder and have it be a book again.....these books never go over about 300 pages .....so i only need 3 number digits

thanks for any help :thumbup

Rob

Link to comment
Share on other sites


I just put some more thought into this ......and the program you suggested will only help me with half of my problem

It was 3am when i wrote the original post ....so i wasnt thinking to clearly......anyways

Go get a magazine .....hold it cover facing up .....Those are the odd pages

book 001.jpg

book 003.jpg

book 005.jpg

.

.

.

Now flip the magazine over and pretend you want to scan the Even pages .......now you need the program to do this

book 116.jpg

book 114.jpg

book 112.jpg

.

.

.

To rename the second batch of files .....I basically need a custom batch file that will prompt for the prefix of the file ......then prompt for which page it starts at (example 116) then rename them backwards to 002

I really dont feel like flipping each page over to be scanned correctly .....then flip them back to normal for storage :no:

Link to comment
Share on other sites

Hope this helps. Just modifiy until it suits you. For example you could use set /p for user prompt for names as I understand you'd like from your first post. To change leading zero's modfiy the section after "lead=" to your desired number of leading zero's.

Ciao and good luck!

@echo off
cls

set myext=txt
set myname=book_

set /a c_zero=900
set /a step=-50
set /a i=0
set /a j=0

echo new filename : %myname%
echo file extension: %ext%
echo start counter : %c_zero%
echo step : %step%
echo:

for /f %%F in ( 'dir %progdir% /A:-D /B ^| findstr /i "%ext%" ^| findstr /v /i "%myname%"' ) do (
set FileN=%%F
set /a i+=1
call :create
)

goto :eof

:create
setlocal ENABLEDELAYEDEXPANSION
set /a j=(%i%-1)*%step%+%c_zero%

set lead=
if %j% lss 1000 set lead=0
if %j% lss 100 set lead=00
if %j% lss 10 set lead=000

echo %FileN% will be copied to %myname%%lead%%j%.%ext%
copy %FileN% %myname%%j%.%ext%
endlocal

Edited by Blub
Link to comment
Share on other sites

This is a VBS script that renames all the files in the folder with the parent path. This uses a

brows for dialog so you can run this script from any where.

EG If you had a folder on C:\MyTest then all the files would be named C_MyTest_Filename

Const MY_COMPUTER = &H11&,WINDOW_HANDLE = 0, OPTIONS = 0
strComputer = "."
Dim RenamF, oShell,Folder, FolderItem
Set oShell = CreateObject("Shell.Application")
Function ReNameFolderContents
Set Folder = oShell.BrowseForFolder(WINDOW_HANDLE, "Select The Folder With The Files To ReName:", OPTIONS, MY_COMPUTER)
If Folder Is Nothing Then
CreateObject("Wscript.Shell").Popup "User Has Cancel", 4,"User Cancel", 0 + 32
Else
Set FolderItem = Folder.Self
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFileList = objWMIService.ExecQuery("ASSOCIATORS OF {Win32_Directory.Name='" & FolderItem.Path & "'} Where ResultClass = CIM_DataFile")
For Each objFile In colFileList
Rn1 = Replace(objFile.Drive,":","_") : Rn2 = Replace(objFile.Path,"\","_")
strNewName = objFile.Drive & objFile.Path & Rn1 & Rn2 & objFile.FileName & "." & objFile.Extension
errResult = objFile.Rename(strNewName)
Next
End If
End Function
ReNameFolderContents

Link to comment
Share on other sites

:huh: Has the following question ever occurred to any one of you above?

He specifies the destination filenames, but what about the source filenames?

...how are you going to ensure that the renaming takes place in the intended order?

I think an actual program instead of a batch file is in order here.

Link to comment
Share on other sites

:huh: Has the following question ever occurred to any one of you above?

He specifies the destination filenames, but what about the source filenames?

...how are you going to ensure that the renaming takes place in the intended order?

I think an actual program instead of a batch file is in order here.

I was hoping the program would import in alphabetical order .......

book 001.jpg

book 002.jpg

.

.

.

Would turn into

book 116.jpg

book 114.jpg

.

.

.

I may be the only person in the world that needs this code :whistle:

It just sucks that the scanner software doesnt anticipate you needing to scan such things ....... :no:

Link to comment
Share on other sites

@LLXX: yes this did occur to me, but since the pages *should* be created in order and numbered incrementally, the batch file *might* just do the trick.

Anyway, it's basically part of my batch file that creates the bulk content of RunOnceEx entries for uA install. See if it helps, if not no time wasted. By the way, I don't use RunOnceEx anymore, but even for that one I still did manual editing in the end as of course a program is also best for this.

To clarify, the script looks for a file pattern (I used txt in the example here because I made a few files with .txt extension to test it quickly. But it can be modified to use any pattern. Also it excludes certain files (here the newly created files, which means you cannot use the same basic file name or it wouldn't do anything. This exclude list could be extended to ignore anything present you don't want processed.

If the source is in random order/has random names, I don't see how it could be done without someone telling which order to use anyway (but usually there is always a way if you try hard enough). But yes, a program would be better yes, much better. I just don't have one :(

I believe the best chance to have it run properly is to scan starting 1 to x uneven in one directory and then x+1 to 2 in reverse order in another. Run the script for the reverse order adjusting start and step -2. This is how I understood your procedure to be?

Didn't look at VBS script but presumably either can be made to do the trick under the condition the source files are in some order. Any is ok as long you know what the order is and it stays like that.

Edited by Blub
Link to comment
Share on other sites

Try this sfx file on a test folder it will do nothing but show you the name changes.

If it does what you want I will change it to rename the files.

Const MY_COMPUTER = &H11&,WINDOW_HANDLE = 0, OPTIONS = 0 : strComputer = "."
Dim Act, Fso, RenamF, oShell,Folder, FolderItem, VBS
Dim strErrResuts, TheFile, OldName, ReNameFile, CT : CT = 0
Set Act = CreateObject("Wscript.Shell") : Set oShell = CreateObject("Shell.Application")
Set Fso = CreateObject("Scripting.FileSystemObject")
VBS = Act.ExpandEnvironmentStrings("%Systemdrive%\Rename_FolderContents_v1.vbs")
Function ReNameFolderContents
Set Folder = oShell.BrowseForFolder(WINDOW_HANDLE, "Select The Folder With The Files To ReName:", OPTIONS, MY_COMPUTER)
If Folder Is Nothing Then
Act.Popup "User Has Cancel", 4,"User Cancel", 0 + 32
Else
Set FolderItem = Folder.Self
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFileList = objWMIService.ExecQuery("ASSOCIATORS OF {Win32_Directory.Name='" & FolderItem.Path & "'} Where ResultClass = CIM_DataFile")
For Each objFile In colFileList
CT = CT + 1
TheFile = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension
OldName = TheFile & vbCrLf & objFile.FileName & "." & objFile.Extension
ReNameFile = objFile.FileName & "-" & CT &"." & objFile.Extension
strNewName = ReNameFile
'''' UNCOMMENT BELOW TO RENAME
' errResult = objFile.Rename(strNewName)
strErrResuts = strErrResuts & vbCrLf & OldName & vbCrLf & strNewName
Next
Act.Popup "Completed Renaming The Files In:" & vbcrlf & FolderItem.Path, 10,"Finished ReName", 0 + 64
End If
End Function
ReNameFolderContents
Act.Popup "Folder Rename List " & vbCrLf & strErrResuts, 30 ,"Rename List", 0 + 32
If Fso.FileExists(VBS) Then : Fso.DeleteFile(VBS) : End If

Edited by gunsmokingman
Link to comment
Share on other sites

Try this sfx file on a test folder it will do nothing but show you the name changes.

If it does what you want I will change it to rename the files.

Doesnt look like that works .....maybe its something that can be fixed ......in this example Image 0004 should have been renamed to Image 0126.......there are 66 image files .....and counting backwards every other number would be equal to that

11420257452136ta.jpg

And if your wondering what i am doing ......I have over 500 videogame magazines .....i am scanning them into electronic format .....rather then deal with the magazines being space hoggers :)

Edited by phillyman2004
Link to comment
Share on other sites

All you have to do is change this to suit your needs.

This start the counter at Zero.
CT : CT = 0

Then it passes the counter number to the filename
ReNameFile = objFile.FileName & "-" & CT &"." & objFile.Extension

If you want to count backward from 66 then start the counter at 66 and change this

CT = CT - 1

This is a redit code the counter start at 100 and goes backward, see attach image for the name changes.

Const MY_COMPUTER = &H11&,WINDOW_HANDLE = 0, OPTIONS = 0 : strComputer = "."
Dim Act, Fso, RenamF, oShell,Folder, FolderItem, VBS
Dim strErrResuts, TheFile, OldName, ReNameFile, CT : CT = 100
Set Act = CreateObject("Wscript.Shell") : Set oShell = CreateObject("Shell.Application")
Set Fso = CreateObject("Scripting.FileSystemObject")
VBS = Act.ExpandEnvironmentStrings("%Systemdrive%\Rename_FolderContents_v1.vbs")
Function ReNameFolderContents
Set Folder = oShell.BrowseForFolder(WINDOW_HANDLE, "Select The Folder With The Files To ReName:", OPTIONS, MY_COMPUTER)
If Folder Is Nothing Then
Act.Popup "User Has Cancel", 4,"User Cancel", 0 + 32
Else
Set FolderItem = Folder.Self
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFileList = objWMIService.ExecQuery("ASSOCIATORS OF {Win32_Directory.Name='" & FolderItem.Path & "'} Where ResultClass = CIM_DataFile")
For Each objFile In colFileList
CT = CT - 1
TheFile = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension
OldName = TheFile & vbCrLf & objFile.FileName & "." & objFile.Extension
' ReNameFile = objFile.FileName & "-" & CT &"." & objFile.Extension
ReNameFile = "Book-0" & CT &"." & objFile.Extension
strNewName = ReNameFile
'''' UNCOMMENT BELOW TO RENAME
' errResult = objFile.Rename(strNewName)
strErrResuts = strErrResuts & vbCrLf & OldName & vbCrLf & strNewName
Next
Act.Popup "Completed Renaming The Files In:" & vbcrlf & FolderItem.Path, 10,"Finished ReName", 0 + 64
End If
End Function
ReNameFolderContents
Act.Popup "Folder Rename List " & vbCrLf & strErrResuts, 30 ,"Rename List", 0 + 32
If Fso.FileExists(VBS) Then : Fso.DeleteFile(VBS) : End If

Edited by gunsmokingman
Link to comment
Share on other sites

All you have to do is change this to suit your needs.
This start the counter at Zero.
CT : CT = 0

Then it passes the counter number to the filename
ReNameFile = objFile.FileName & "-" & CT &"." & objFile.Extension

If you want to count backward from 66 then start the counter at 66 and change this

CT = CT - 1

This is a redit code the counter start at 100 and goes backward, see attach image for the name changes.

Const MY_COMPUTER = &H11&,WINDOW_HANDLE = 0, OPTIONS = 0 : strComputer = "."
Dim Act, Fso, RenamF, oShell,Folder, FolderItem, VBS
Dim strErrResuts, TheFile, OldName, ReNameFile, CT : CT = 100
Set Act = CreateObject("Wscript.Shell") : Set oShell = CreateObject("Shell.Application")
Set Fso = CreateObject("Scripting.FileSystemObject")
VBS = Act.ExpandEnvironmentStrings("%Systemdrive%\Rename_FolderContents_v1.vbs")
Function ReNameFolderContents
Set Folder = oShell.BrowseForFolder(WINDOW_HANDLE, "Select The Folder With The Files To ReName:", OPTIONS, MY_COMPUTER)
If Folder Is Nothing Then
Act.Popup "User Has Cancel", 4,"User Cancel", 0 + 32
Else
Set FolderItem = Folder.Self
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFileList = objWMIService.ExecQuery("ASSOCIATORS OF {Win32_Directory.Name='" & FolderItem.Path & "'} Where ResultClass = CIM_DataFile")
For Each objFile In colFileList
CT = CT - 1
TheFile = objFile.Drive & objFile.Path & objFile.FileName & "." & objFile.Extension
OldName = TheFile & vbCrLf & objFile.FileName & "." & objFile.Extension
' ReNameFile = objFile.FileName & "-" & CT &"." & objFile.Extension
ReNameFile = "Book-0" & CT &"." & objFile.Extension
strNewName = ReNameFile
'''' UNCOMMENT BELOW TO RENAME
' errResult = objFile.Rename(strNewName)
strErrResuts = strErrResuts & vbCrLf & OldName & vbCrLf & strNewName
Next
Act.Popup "Completed Renaming The Files In:" & vbcrlf & FolderItem.Path, 10,"Finished ReName", 0 + 64
End If
End Function
ReNameFolderContents
Act.Popup "Folder Rename List " & vbCrLf & strErrResuts, 30 ,"Rename List", 0 + 32
If Fso.FileExists(VBS) Then : Fso.DeleteFile(VBS) : End If

So in my example right now there are 66 image files .......the last image should be renamed from

Nintendo Power Issue 180 - 0066.jpg to Nintendo Power Issue 180 - 0002.jpg

Nintendo Power Issue 180 - 0065.jpg to Nintendo Power Issue 180 - 0004.jpg

Nintendo Power Issue 180 - 0064.jpg to Nintendo Power Issue 180 - 0006.jpg

Etc....

See .....the images that were scanned ....numerically go in order .....but i need them renamed backwards skipping every other number

Regular renamer programs work fine on the first half of the book .....because all i am doing there is renaming the files and skipping each number

Flipping the book over to scan the Even pages ....results in the magazine being last page up .....which is where my situation comes into play

So basically the program i guess would need to ask for the prefix of what i wanted the file to be named

Nintendo Power Issue 180 -

Then It would need to know how many image files total?

66

It would then know the first Image file that it found would be renamed to

Nintendo Power Issue 180 - 0132.jpg

Then it would move to the next file .....and rename it

Nintendo Power Issue 180 - 0130.jpg

and so on .....Like i said the Odd pages are no problem because they go in order .....and i can use a standard renamer program with enumeration = 2 and starting at 0001

I really do appriciate this help you guys are giving me

Rob

Edited by phillyman2004
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...