[动作需求] 批量重命名文件 根据文件的创建日期顺序 给文件加上数字前缀 01 02 03 04 05 ...98 99
powershell脚本写好了
$files = Get-ChildItem *.txt | Sort-Object -Property CreationTime $digits = $files.Count.ToString().length $i = 1 foreach ($file in $files) { $prefix = "{0:d$digits}" -f $i $file | Rename-Item -NewName { $prefix + "-" + $_.name } $i++ }
param ( [Parameter(Mandatory = $true)]$filePathsStr ) $files = @() ($filePathsStr -split '\r?\n').Trim() | ForEach-Object { $files += (Get-Item -Path $_) } $files = $files | Sort-Object -Property CreationTime $digits = $files.Count.ToString().length $i = 1 foreach ($file in $files) { $prefix = "{0:d$digits}" -f $i $file | Rename-Item -NewName { $prefix + "-" + $_.name } $i++ }
powershell脚本写好了