Scripting Help - Set File Date based on Folder Name (or How to Get Help)

Copper Contributor

Hi Community - I need help and hoping this is the place for it.  Or if you can recommend where I should ask for this help, I would appreciate it.

 

Obstacle:  I have many files that I need the date changed to the name of the folder they exist within.  I would like a script that would cycle through each folder and do this automatically.   Let me know what can be done and am open to suggestions.

 

JCombs_0-1619120166188.png

 

2 Replies

Hello @JCombs,

I think this should give you some ideas to start from. There they are getting date from file name and in your case you need to do it from parent folder.

 

Hope that helps.

you can you the below 1 liner to grab the folder name and load into a variable
$test = "C:\Temp\2005-12-15\FH0000013.jpg"
$test.split("\")[-1] will return FH0000013.jpg
$test.split("\")[-2] will return 2005-12-15 being the dated folder you are wanting

store it into variable you can then reuse in the rename
$fdate = $test.split("\")[-2]