2017-07-04 46 views
-5

第一個字符排序文件誰能幫助這個家庭項目?Powershell:按名稱

我在嘗試排序一個500gb +目錄中充滿隨機文件。

我想這些文件到一個名爲 'A', 'B' 的子目錄 'C' ..., '1', '2', '3' 排序,...

################################################### 
# I've created a test directory to try my script against 
################################################### 
<# Start 7/4/2017 #> 

Set-Location 'D:\IT Notes\psroot' 


<# Make directories A..Z#> 

65..90 | % {md ("{0}" -f [char]$_)} 


<# Make a list of 0-9, A-Z, & a-z #> 
$chars = [char[]] ([char]'0'..[char]'9' + [char]'A'..[char]'Z' + [char]'a'..[char]'z') 


<# Use chars list to create random.txt file#> 
(1..100).ForEach({-join (Get-Random $chars -Count 10) | Add-Content random.txt }) 


<# Save random.txt list to a variable#> 
$random = (Get-Content .\random.txt) 


<# Create files & add .txt extension #> 
New-Item $random -ItemType file | Rename-Item -NewName {$_.name + ".txt"} 

################################################### 

現在我該如何將所有內容排序到他們尊重的目錄中?

感謝您的幫助提前!

+6

所以,所有的代碼與你的問題無關,你的問題是「爲我寫這個腳本?」 - 關注話題,過於寬泛,或者沒有研究努力,或者什麼也不贊成。 https://stackoverflow.com/q/38485877/478656和https://stackoverflow.com/q/21117208/478656和https://stackoverflow.com/q/41467996/478656和https://stackoverflow.com/ q/11777466/478656和https://stackoverflow.com/q/7316797/478656和https://stackoverflow.com/q/30727325/478656和https://stackoverflow.com/q/37617391/478656都是更多 - 或者更少的同一個問題,並且應該爲你提供很多方法。 – TessellatingHeckler

回答

0

這讓我整個上午都很累,但我終於找到了工作!

對於那些誰有興趣使用PowerShell來清理這些大和不羈的目錄,你的歡迎:]

########################## 
# Create directory A-Z 
65..90 | % {md ("{0}" -f [char]$_)} 


# Starting value = A 
$upcaseN = 65 


# Run loop while $upcase less than or equall to 90 
while ($upcaseN -le 90) { 

# Convert $upcase from int to char 
$upcase = [char]$upcaseN 

# Move items to respected directories 
Move-Item $upcase* $upcase -ErrorAction SilentlyContinue 

# Increase starting value 
$upcaseN++ 

} 
########################### 



########################### 
# Create directory 0-9 
0..9 | % {md ("{0}" -f $_)} 

# Starting value = 0 
$notaletter = 0 

while ($notaletter -le 9){ 
Move-Item $notaletter* $notaletter -ErrorAction SilentlyContinue 
$notaletter++ 

} ################ ############