Link to home
Start Free TrialLog in
Avatar of icg_team
icg_team

asked on

Update modified date of parent/grand parent folder when sub-file is updated

I'm on a Mac, and working on a Bash script to handle this.

I have a folder hierarchy containing PO files ready for processing (RFP) and we have a script that looks at modified dates of folders that end in "-RFP". I don't have access to modify the processing job script.

If the "-RFP" folder's modified date is within last 24 hours, then the processing job will run on the folder. This works fine on new folders, but does not pick up edits to sub-files or folders with more complex sub-folders.

Users are updating files in sub-folders at varying depths below the "-RFP" folders, and they are expecting that the processing job will run against those folders. I'm looking to run a find-&-touch cron job to update the modified date of parent and grand-parent "-RFP" folders.

Here's a sample of the hierarchy.

Root
 --2015_Folder
      --PO48484_Folder_RFP (need to update mod date)
           --File1.txt (modified in last day)
      --PO23939_Folder_RFP (need to update mod date)
            --POComponent_Folder1
                --File3.txt (modified in last day)
                --File4.txt (modified three weeks ago)
            --POComponent_Folder2
                --File5.txt (modified three weeks ago)
                --File6.txt (modified three weeks ago)

I want to be able to find all modified .txt files in the folder hierarchy, and then update the modified date of the containing "-RFP" folder, regardless of file depth within the associated RFP folder.

Scraping together my very rusty bash knowledge and borrowing from elsewhere, I've got the following which should touch the parent folders, but not specifically the "-RFP" folders if the text files are down a layer or more.

find . -type f -mtime -1 -name '*.txt' -print0 \ | ( IFS=$'\0' ; while read -d "" FILE ; do echo touch -r "$FILE" "$(dirname "$FILE")" ; done )

Open in new window


What should I be using to look for the -RFP suffix?

Any help would be appreciated!
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial