Reputation: 23
I have searched high and low for a way to batch rename files in windows. I'm not particularly worried what language it uses as long as it works. We use a scanner at work to scan invoices, we input the invoice number on the scanner and it saves the files as PDF.
The problem is they are saved as yyyymmddhhmmss_invoicenumber.pdf
We import these into an access program which uses the invoices based on the file name, but doesn't recognise the date/timestamp on the file name. So every day we have to go through about 80 invoices and rename them to remove everything up to the invoice number.
Every script I've found adds the date time tithe filename, but I want to remove it. I have only ever done a bit of PHP and HTML but I need something that will work on windows.
Is there anything anyone can suggest? ideally I would like it to be a batch script or a button that I can click to automate this process.
Any help is greatly appreciated.
Upvotes: 0
Views: 821
Reputation: 263
as long as the filename is yymmddxxx_invoicenumber.pdf then this batch script will work
@echo off
for /f "delims=_ tokens=1,2" %%a in ('dir /b *_*.pdf') do @echo ren %%a_%%b %%b
(remove the echo to have it actually rename the files)
(remove the %%a to %a if running from command line)
if you want to specify a year type (or mm or dd), then mod the interior command to
('dir /b yy*_*.pdf') or
('dir /b ??mm*_*.pdf'),
leave the echo in so that it is non destructive on first runs
on the above substitute yy or mm or dd with acutal values.
happy batching
Upvotes: 2