WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Franais)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
Rename files by swapping year with month (Read 80 times)
Lancealots
YaBB Newbies
*
Offline



Posts: 1
Rename files by swapping year with month
Mar 28th, 2018 at 9:39pm
 
We currently have a process that integrates PDFTK to merge PDF'S based on name however the order of the PDFs are not the way they should be.

The names of the PDFs all come in the same format:
Num_Month-Day-Year_Doc_Type.PDF

We would like to have it shown below where the year and month swap

What we have:
5859752023601609_12-16-2017_monthly_statement

What we want:
5859752023601609_2017-16-12-_monthly_statement
(this puts the files in the order we need before the merge)

*** issue:  We want this renaming to happen before a new trigger is ran that runs a batch file to merge. Can we have a process set off another process?

We tried including some rename commands in the batch file before the merge however have not been able to get it to run.
Tried:
rename -n 's/^([0-9]{16})\_([0-9]{2})\-([0-9]{2})\-([0-9]{4}) (.*)\.PDF$/$4 $3-$1-$2.PDF/' *
And:
rename 's/^(*)\_(*)\-(*)\-(*)\_(*).PDF$/$1 $4-$3-$2_$5_.pdf/' *


BTW we love your program!!! Smiley
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2268
The Netherlands
Re: Rename files by swapping year with month
Reply #1 - Mar 30th, 2018 at 6:24am
 
Hi,

Is the "Num" part fixed length, always 16 characters? In that case you can do something like the following in your bat script
SET NUM=%WD_FILE_N:~0,16%
SET MON=%WD_FILE_N:~17,2%
SET DAY=%WD_FILE_N:~20,2%
SET YEAR=%WD_FILE_N:~23,4%
SET REMAINDER=%WD_FILE_N:~28%
and build a new filename from these.

Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Page Index Toggle Pages: 1