Trang chủ / Tool / Powershell

Powershell

Yêu cầuThao tácLệnhDemoGhi chúVí dụ
mở power shell ở một folderShift+chuật phảicd “path folder”
Tên file
Chuyển tất cả tên file thành chữ hoaDir -Recurse | Rename-Item -NewName {$_.BaseName.ToUpper() + $_.Extension.ToUpper()} 
Chuyển tất cả tên file thành chữ thườngDir -Recurse | Rename-Item -NewName {$_.BaseName.Tolower() + $_.Extension.Tolower()} 
Thay thế một ký tự trong tên filedir | Rename-Item -NewName {$_.name -replace “ký tự bị thay thế”, “ký tự được thay thế”}Không ghi đè
Thêm dấu gạch chéo \trước ký tự đặc biệt (){}[] để thay thế
dir | Rename-Item -NewName {$_.name -replace ” “, “-“}
thêm ký tự vào đầu tên filedir -exclude “add text*” | Rename-Item -NewName {“add text” + $_.name}dir -exclude “du-an-biet-thu-binh-chanh-*” | Rename-Item -NewName {“vu khi genshin impact ” + $_.name}
thêm ký tự vào cuối tên filedir | Rename-Item -NewName {$_.basename + “-tuong-lien-quan-mobile” + $_.extension}dir | Rename-Item -NewName {$_.basename + “-thanh-di-vat-genshin-impact” + $_.extension}
Tạo hàng loạt thư mục
“thu muc 1”, “thu muc 2″,”thu muc 3” | %{New-Item -Name “$_” -ItemType “Directory”}
thay thế số ký tự trong hàng loạt file
get-childitem *.mp3 | foreach { rename-item $_ $_.Name.Replace(“ký tự bị thay thế”, “ký tự thay thế”) }get-childitem *.png | foreach { rename-item $_ $_.Name.Replace(“-“, ” “) }
xoá một số ký tự trong hàng loạt file
get-childitem *.mp3 | foreach { rename-item $_ $_.Name.Replace(“ký tự cần xoá”, “”) }
Đổi tên file thành chữ thường
Get-ChildItem *.jpg | Rename-Item -NewName {$_.FullName.ToLower()}