2017-07-04 6 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

さて、すべてのコードはあなたの質問とは無関係です。あなたの質問は「このスクリプトを私のために書くのですか? - トピックを外して、広すぎる、あるいは研究努力をしないために、または何かをdownvote。 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++ 

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

関連する問題