August 18, 2014 at 7:40 am
Hopefully this posts is okay here...
I am trying to write a PowerShell script to rename some files, but am having some trouble.
I've got the following file:
cust140817.fco
In the following directory:
C:\Temp\Cust
I want the file named changed to the following:
cust140818.fco
Pretty much just need one added to the "dd" part of the date.
I have the following script:
#enter the directory you want to rename the files of
$mydir = 'C:\Temp\Cust\*.fco'
$today = get-date
$yesterdayShortDate = $today.ToShortDateString() -replace '/', '_'
#no confirmation/undo after running this. Make sure you have the correct directory in the $myDir variable
get-childitem $mydir -recurse | where {$_.attributes -ne 'Directory'} | ? { $newname = ($_.name -replace $_.extension, '') + '_' +$yesterdayShortDate + $_.extension
rename-item $_.fullname $newname}
The result of the above is:
cust140817_8_18_2014.fco
If anyone could provide some guidance on this, I would greatly appreciate it!!
Viewing 0 posts
You must be logged in to reply to this topic. Login to reply