Forum Discussion
JCombs
Apr 22, 2021Copper Contributor
Scripting Help - Set File Date based on Folder Name (or How to Get Help)
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.
- AndySvintsSteel Contributor
- SteveMacNZIron Contributoryou 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]