Powershell:按名称的第一个字符对文件进行排序

Powershell:按名称的第一个字符对文件进行排序,powershell,filesystems,powershell-4.0,Powershell,Filesystems,Powershell 4.0,有人能帮忙做这个家庭项目吗 我正在尝试对一个500 GB以上的目录进行排序,其中包含大量随机文件 我想将这些文件排序到名为“A”、“B”、“C”…、“1”、“2”、“3”的子目录中 ################################################### # I've created a test directory to try my script against ##################################################

有人能帮忙做这个家庭项目吗

我正在尝试对一个500 GB以上的目录进行排序,其中包含大量随机文件

我想将这些文件排序到名为“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"}

###################################################
现在,我如何将所有内容排序到他们的目录中


提前谢谢你的帮助

这花了我一上午的时间,但我最终还是成功了

对于那些有兴趣使用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++
}

Soo,所有代码都与您的问题无关,您的问题是为我编写此脚本?-离题,太宽泛,或者对没有研究成果投反对票,或者什么的。这些或多或少都是同一个问题,应该会给你带来很多帮助。