Batch Rename

Don't know where to start, or stuck on a certain problem? Drop by and tell us about it. Feel like helping others? Start here.

Moderator: peterZ

Post Reply
swizzle
Posts: 4
Joined: 19 Dec 2022, 21:29
Number of books owned: 3
Country: United States

Batch Rename

Post by swizzle »

I do destructive scanning. Currently working through some small magazines so instead of cutting the spine I'm just removing the staples and scanning both pages (and sides) at the same time.

These are very old yellow magazine pages at this point so I run them through Scan Tailor Advanced to clean them up. I ultimately compress the tif files into a cbr. But this means I need to rename the files to be in the correct order. For example the file names and actual page names are:

Scan_0001_1L.tif [page 96, as there are 96 total files in this set of scans]
Scan_0001_2R.tif [page 1]
Scan_0002_1L.tif [page 2]
Scan_0002_2R.tif [page 95]
Scan_0003_1L.tif [page 94]
Scan_0003_2R.tif [page 3]
Scan_0004_1L.tif [page 4]
Scan_0004_2R.tif [page 93]
Scan_0005_1L.tif [page 92]
Scan_0005_2R.tif [page 5]
.. and so on

There is a clear pattern with the page order but I'm currently renaming the files by hand. Does anyone know of software or a script which could do this for me?
cday
Posts: 451
Joined: 19 Mar 2013, 14:55
Number of books owned: 0
Country: UK

Re: Batch Rename

Post by cday »

There are many software renumbering utilities, but I am not aware of one that supports this kind of problem, and doubt if there is one although it might just possibly be worth searching online.

Some years ago I scanned a batch of club magazines by removing the staples and then feeding the loose sheets through a sheet feeder, as you are doing. I also scanned double-sided. I then developed a Windows batch file .bat to process the resulting scans and number the resulting pages correctly. My utility split the resulting two-page scans into single pages using the command line NConvert utility, rather than using Scan Tailor as you are doing. If I had needed I could also have enhanced the scans, for example using a levels adjustment.

The vital step of then developing an algorithm to renumber the resulting page files was developed one morning in a quiet coffee shop with the aid of copious coffee! As you have said, it is easy to see that the scan file numbers follow a pattern, but not quite so easy to conceive an algorithm to automate the renumbering. Some people might achieve that step more easily than others but at least I got there without too much trouble!

A renumbering algorithm needs to know the total number of pages in the source document. That could be entered at an onscreen prompt when the utility starts, but I had already chanced on a small piece of very cryptic code which could count the number of files in a folder, so I used that.

My code performed more operations than you need, your need only being for a renumbering utility that accepts single-page files numbered in the sequence in which they are produced, which won't be the same as for my two-page scans. My code was also uncommented, so I would have some trouble understanding it myself now, so I won't immediately dig it out.

I would suggest that you produce a set of test source files as I did, which can assist with both conceiving the required algorithm, and then enabling correct operation to be confirmed when the code is tested. I took three or four sheets of plain paper, folded them as if they were a magazine, and then clearly numbered the pages so that the correct page sequence could be verified on the screen after the algorithm was run. Then scan and process the sheets *exactly* as if you were scanning another magazine.

If you can then post the resulting test files in a ZIP, either as an attachment if the file is small enough to attach, or provide a download link, it might inspire someone to try developing a small utility you that can use. Possibly me, but I am overstretched at the moment, and I know from experience that sort of coding might take some time. My utility used Windows CMD (cmd.exe, which is DOS on steroids) which is included in all modern Windows versions for the various operations required.

Note that at the detailed level when coding at the Windows command line, source files (your scans) are not read in the modern Windows sort order 1,2,3... but in an earlier sort order where files numbered 1,2,3 ... 10, 11, 12, ... are read in the order 1, 11,12 ... 2... , 3... When a multipage file such as a PDF is produced that can result in the pages not being in the correct sequence. That shouldn't be an issue as your file numbers do have leading zeros, but is a trap for the unwary in other situations which has sometimes caused great confusion.

Or, of course, someone who is a serious coder might be able to produce a small utility using more professional tools... ;)
Konos93a
Posts: 195
Joined: 19 Sep 2016, 10:00
E-book readers owned: kobo aura,kindle 1,kindle pw3,pocketbook inkpad 2
Number of books owned: 3000
Country: greece

Re: Batch Rename

Post by Konos93a »

cday
Posts: 451
Joined: 19 Mar 2013, 14:55
Number of books owned: 0
Country: UK

Re: Batch Rename

Post by cday »

But do either of those utilities support swizzle's sheet-fed scans issue, a quite unusual need?
swizzle
Posts: 4
Joined: 19 Dec 2022, 21:29
Number of books owned: 3
Country: United States

Re: Batch Rename

Post by swizzle »

I appreciate the suggestions which have been posted but have modified my process to just cut these small magazines as well so the file names are ordered.
cday
Posts: 451
Joined: 19 Mar 2013, 14:55
Number of books owned: 0
Country: UK

Re: Batch Rename

Post by cday »

Thanks for reporting back!

It could be useful if one day someone does produce a small utility that can rename images produced by scanning loose sheets from a magazine or book through a scanner sheet feeder. Such a utility would also need to support cropping the resulting two-page scans into separate pages as well as renaming. There are probably only two ways to feed loose sheets through a sheet feeder, either scanning single or double sided, although an option to invert scans that are inverted could be added. Ideally, such a utility would be cross-platform and have a graphical user interface.

Scanning a magazine or book using a sheet feeder after removing the staples does allow the possibility of reassembling the publication after scanning, by reinserting the staples removed or otherwise.
Christiaan
Posts: 1
Joined: 26 Apr 2023, 08:56
Number of books owned: 0
Country: Netherlands

Re: Batch Rename

Post by Christiaan »

Hi,

I scan alot of magazines (old tv/radio guides) and in order to save the magazine I also remove the staples. My scanner, a Fujitsu 6770 scans both sides in one run and cuts the pages in half. So one run gives me 4 scans. (page 1, 4, 2 and 3) Two sheets gives me page 1, 8, 2, 7, 3, 6, 4 and 5.
To put the scans in the correct order I asked a friend of mine to make a program to do this for me. It doesn't matter how many pages there are, it puts them in the correct order. For TIFF and jpg.

The program (only Windows) is in Dutch, but I can ask to make an English version...

Gr. Christiaan
swizzle
Posts: 4
Joined: 19 Dec 2022, 21:29
Number of books owned: 3
Country: United States

Re: Batch Rename

Post by swizzle »

I would love to get the program - even if it's in Dutch - but I imagine there would be interest in a English version if it can be translated. That utility would mean these magazines could be saved after instead of being discarded.
cday
Posts: 451
Joined: 19 Mar 2013, 14:55
Number of books owned: 0
Country: UK

Re: Batch Rename

Post by cday »

Very interesting... :D

Does your friend's tool run with a user interface on Windows, and might he be prepared to modify it to accept sheets scanned either single- or double-sided?
swizzle
Posts: 4
Joined: 19 Dec 2022, 21:29
Number of books owned: 3
Country: United States

Re: Batch Rename

Post by swizzle »

I circled back to this as I would really like to do scans of full pages without cutting if possible. I ended up finding a post which discusses this issue, and offers a solution through an Excel macro >

https://irfanview-forum.de/forum/progra ... nts/10411-

Unfortunately, I don't use Excel and the macro doesn't work "out of the box" with OpenOffice Calc. I've enabled the Executable code option for Microsoft Excel 97/2000/XP compatibility, but still get an error trying to run the code.

Is anyone here proficient with macro's to get this code working with OpenOffice Calc?
Post Reply