我正在尝试编写一个 Powershell 脚本,该脚本将:
- 从根目录递归搜索 -
排除具有现有“yyyyMMdd”文件名前缀的
文件 - 根据特定的 LastWriteTime,使用“yyyyMMdd”文件名前缀重命名上面未排除的文件
注意:理想情况下,该脚本应包含所有文件类型扩展名
我自己也尝试过,但这似乎超出了我的能力范围,因为我的尝试进展并不顺利。
提前致谢。
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-%d@%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 …Run Code Online (Sandbox Code Playgroud) powershell ×1