E
Evan Platt
So I'm looking to rename all the files in a directory appending the
date / time.
I found the powershell script at
http://ss64.com/ps/syntax-stampme.html :
#StampMe.ps1
param( [string] $fileName)
# Check the file exists
if (-not(Test-Path $fileName)) {break}
# Display the original name
"Original filename: $fileName"
$fileObj = get-item $fileName
# Get the date
$DateStamp = get-date -uformat "%Y-%m-%[email protected]%H-%M-%S"
$extOnly = $fileObj.extension
if ($extOnly.length -eq 0) {
$nameOnly = $fileObj.Name
rename-item "$fileObj" "$nameOnly-$DateStamp"
}
else {
$nameOnly = $fileObj.Name.Replace( $fileObj.Extension,'')
rename-item "$fileName" "$nameOnly-$DateStamp$extOnly"
}
# Display the new name
"New filename: $nameOnly-$DateStamp$extOnly"
But this doesn't appear to work on a batch basis, ie
powershell ./stampme.ps1 G:\test\*.*
(or G:\test ).
Am I missing something obvious? This is Windows 8 if it matters.
(Yes, I realize this is a Win7 group but I beleve the PS is the same)
Thanks.
date / time.
I found the powershell script at
http://ss64.com/ps/syntax-stampme.html :
#StampMe.ps1
param( [string] $fileName)
# Check the file exists
if (-not(Test-Path $fileName)) {break}
# Display the original name
"Original filename: $fileName"
$fileObj = get-item $fileName
# Get the date
$DateStamp = get-date -uformat "%Y-%m-%[email protected]%H-%M-%S"
$extOnly = $fileObj.extension
if ($extOnly.length -eq 0) {
$nameOnly = $fileObj.Name
rename-item "$fileObj" "$nameOnly-$DateStamp"
}
else {
$nameOnly = $fileObj.Name.Replace( $fileObj.Extension,'')
rename-item "$fileName" "$nameOnly-$DateStamp$extOnly"
}
# Display the new name
"New filename: $nameOnly-$DateStamp$extOnly"
But this doesn't appear to work on a batch basis, ie
powershell ./stampme.ps1 G:\test\*.*
(or G:\test ).
Am I missing something obvious? This is Windows 8 if it matters.
(Yes, I realize this is a Win7 group but I beleve the PS is the same)
Thanks.