How to avoid renaming already renamed files w/DateTime stamp

Bulk Rename Utility How-To's

How to avoid renaming already renamed files w/DateTime stamp

Postby TempusFugit » Wed Feb 16, 2022 6:25 am

Hi all, thanks in advance for any assistance you may provide!

Situation:
1. The source application generates a file like "Inventory.XML" every 10 minutes that gets uploaded to my FTP server.
2. Ten minutes later, the source application will generate a new file named "Inventory.XML", which will overwrite the previously existing file on the FTP server once uploaded
3. I want to keep the previous file on the FTP site and rename it with a dateTime stamp so that it is not overwritten by a subsequent FTP transfer of a file with the same name

Requests:
1. How do I apply a dateTime stamp Suffix to just those files that don't already have one?
a. Note, using BRU section 8 "Auto Date" Suffix mode with Format YMD HMS works fine for the first pass, but then keeps appending dates to the filename on each subsequent pass, so I figure I need to apply a Regex or Mask, etc., which is what I need help with.
2. How do I schedule BRU to apply this routine automatically?

Desired Result Example:
10am - Inventory.XML is uploaded to FTP site
10:01am - BRU renames Inventory.XML to Inventory20220215100103.XML
10:10am - new Inventory.XML is uploaded to FTP site
10:11am - BRU skips Inventory20220215100103.XML (i.e. leaves the filename intact because is already has the dateTime suffix) AND renames the new Inventory.XML to Inventory20220215101101.XML
10:20am - new Inventory.XML is uploaded to FTP site
10:21am - BRU leaves the two existing filenames intact, but renames the third Inventory.XML to Inventory20220215102159.xml

So, in this example I would wind up with three "Inventory" files each with only one instance of the dateTime suffix.
TempusFugit
 
Posts: 4
Joined: Wed Feb 16, 2022 5:58 am

Re: How to avoid renaming already renamed files w/DateTime stamp

Postby Luuk » Wed Feb 16, 2022 10:13 am

1: Since the filename is always to be the same, the Filters(12) could use a "Mask" like... Inventory.xml
2: The bru cannot apply this every 10-minutes by itself, without another application to auto-click its buttons.
Without having another application to conduct auto-clicking, I would probably use the brc-commandline instead.

Then you could just make a script like...
C:\PathTo\brc64.exe /dir:"C:\PathTo\YourFolder" /pattern:Inventory.xml /AppendDate:N:S:20::9: /execute

And depending on what shell is granted on the server, just include some code to run this script every 10-minutes.
On Windows, you could either create a task to run it every 10 minutes, or make an always running script like...

@echo off
:begin
timeout /t 600 /nobreak >nul
brc64.exe /Dir:"C:\PathTo\YourFolder" /Pattern:Inventory.xml /AppendDate:N:S:20::9: /execute
goto begin
Luuk
 
Posts: 689
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to avoid renaming already renamed files w/DateTime stamp

Postby TempusFugit » Wed Feb 16, 2022 7:10 pm

Luuk, thanks very much for your assistance! I will attempt your suggestions and reply back in a few days with my result. Cheers!
TempusFugit
 
Posts: 4
Joined: Wed Feb 16, 2022 5:58 am

Re: How to avoid renaming already renamed files w/DateTime stamp

Postby TempusFugit » Thu Feb 17, 2022 5:38 pm

Hi Luuk,

Using this regex pattern ^Inventory[0-9]{0,3}\.xml in the Filters(12) Mask together with Subfolders, and the Add(7) and AutoDate(8) features works perfectly via the GUI program!
Image

However, I've not been able to reproduce those results via the cmd utility. I've tried some different variations without success, but below is what I think I want to run. It runs without error showing "Processing Folder...", but the filenames are not actually changed thereafter.
C:\BRC64.EXE /DIR:"C:\Data\FTP-DIRs\ParentFolderHere" /PATTERN:^Inventory[0-9]{0,3}\.xml /RECURSIVE /NOFOLDERS /APPENDDATE:N:S:_::9: /EXECUTE

Can you or anyone assist with how to reproduce my GUI result with the command line parameters? Thank you!
TempusFugit
 
Posts: 4
Joined: Wed Feb 16, 2022 5:58 am

Re: How to avoid renaming already renamed files w/DateTime stamp

Postby Luuk » Thu Feb 17, 2022 9:51 pm

Its unfortunate, but /Pattern: wont conduct the regular-expressions, I wish there can be /RegexPattern.
So the best it can do is like /Pattern:"Inventory.xml Inventory?.xml Inventory??.xml Inventory???.xml".
But each "?" will only let the shell test for "1-character" instead of "1-number" like the regex.

Im making a very bad typo using the "N" for "Now-Date"... This should have been "C" for "Create-Date" !!!
With files getting created at 10-minute increments, /AppendDate needs the "C" to invent unique dateTimes.
Also, the "9" only adds 2-digit years, but you could change "_" --> "_20" to get all four digits.

I'm not understand if Inventory01.xml ===> 'Inventory_CreateDate.xml' -or- 'Inventory01_CreateDate.xml' ???
But to remove these numbers, then brc64 needs /RegExp:"^(Inventory)\d{0,3}$:\1" before the /AppendDate.
So its unfortunate, but Im thinking the whole command to be a very, very long line, something like...
Code: Select all
C:\brc64 /dir:"C:\Data\FTP-DIRs" /pattern:"Inventory.xml Inventory?.xml Inventory??.xml Inventory???.xml"  /recursive  /nofolders  /regexp:"^(Inventory)\d{0,3}$:\1"  /AppendDate:C:S:_20::9:  /execute                    ..

You can remove /execute to preview the invented new-names on the commandline, or if its a whole lot to preview...
Just replace /execute with ">C:\PathTo\preview-file.txt" so then just looking at the preview-file instead.
Luuk
 
Posts: 689
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to avoid renaming already renamed files w/DateTime stamp

Postby Luuk » Thu Feb 17, 2022 10:16 pm

Im making another typo... To make a preview-file, replace /execute with >"C:\PathTo\preview-file.txt"
The > should not be inside of double-quotes.
Luuk
 
Posts: 689
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to avoid renaming already renamed files w/DateTime stamp

Postby TempusFugit » Thu Feb 17, 2022 11:16 pm

Luuk, thank you very much! I am so pleased by your support, and my initial foray into this community forum and the tremendous assistance everyone is giving to each other is really great to see. With your guidance I was able to get to the final state I wanted using below (in case others would be interested to achieve a similar result):

---
Command Line:
C:\brc64.exe /dir:"C:\PutTheParentDirectoryContainingTheSubdirectoriesYouWantToSpanHere" /pattern:"Inventory.xml Inventory?.xml Inventory??.xml Inventory???.xml" /recursive /nofolders /AppendDate:C:S:_20::9: /EXECUTE

Test Result (substituting >"C:\preview-file.txt" for /execute):
Processing Folder C:\Data\FTP-DIRs\MXDNY\PortalMX\TestClient\Staging\RetailProFeeds\FromRPro\

Processing Folder C:\Data\FTP-DIRs\MXDNY\PortalMX\TestClient\Staging\RetailProFeeds\FromRPro\Archive\

Processing Folder C:\Data\FTP-DIRs\MXDNY\PortalMX\TestClient\Staging\RetailProFeeds\FromRPro\Inventory\

Processing Folder C:\Data\FTP-DIRs\MXDNY\PortalMX\TestClient\Staging\RetailProFeeds\FromRPro\Sub1\
Filename Inventory.xml would be renamed to Inventory_20220215223456.xml
Filename Inventory000.xml would be renamed to Inventory000_20220216194417.xml
Filename Inventory001.xml would be renamed to Inventory001_20220216194417.xml


Processing Folder C:\Data\FTP-DIRs\MXDNY\PortalMX\TestClient\Staging\RetailProFeeds\FromRPro\Sub2\
Filename Inventory.xml would be renamed to Inventory_20220217152445.xml
Filename Inventory000.xml would be renamed to Inventory000_20220217152445.xml
Filename Inventory001.xml would be renamed to Inventory001_20220217152445.xml

Processing Folder C:\Data\FTP-DIRs\MXDNY\PortalMX\TestClient\Staging\RetailProFeeds\FromRPro\Sub3\
Filename Inventory.xml would be renamed to Inventory_20220217152506.xml
Filename Inventory000.xml would be renamed to Inventory000_20220217152506.xml
Filename Inventory001.xml would be renamed to Inventory001_20220217152506.xml
---

My case is closed. Thank You!
TempusFugit
 
Posts: 4
Joined: Wed Feb 16, 2022 5:58 am


Return to How-To


cron