I've written a (very) simple script that appends the current date to a given file name in PowerShell, and I've set it up with a SendTo shortcut for easy access.
However, it doesn't handle file names with spaces in them very well. If a file name is "thisFile.txt" it correctly adds the date, making it "thisFile.txt.20121227", but if the file name is "this File.txt" it doesn't work from the SendTo shortcut I've set up.
It does work from the command line for both types of file names, however, and I've been scratching my head trying to figure out why.
This is the snippet of code I've been using:
$enddate = (Get-Date).toString("yyyyMMdd")
$filename = $arg
foreach ($filename in $args) {
Rename-Item $filename $filename"."$enddate
}
This is in the Target field for the shortcut I've set up:
"%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe " -NonInteractive -WindowStyle Hidden -NoProfile -noexit &"C:\Scripts\adddate.ps1"
Using the -f
switch instead of the ampersand (&
) in front of the script path should solve your issue.