-5

Can anyone help with this home project?

I'm attempting to sort a 500gb+ directory full of random files.

I'd like to sort these files into sub-directories named '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"}

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

Now how do I sort everything into their respected directory?

Thanks for your help in advance!

  • 6
    Soo, all the code is irrelevant to your question, and your question is "write this script for me?" - off topic, too broad, or downvote for no research effort, or something. https://stackoverflow.com/q/38485877/478656 and https://stackoverflow.com/q/21117208/478656 and https://stackoverflow.com/q/41467996/478656 and https://stackoverflow.com/q/11777466/478656 and https://stackoverflow.com/q/7316797/478656 and https://stackoverflow.com/q/30727325/478656 and https://stackoverflow.com/q/37617391/478656 are all more-or-less the same question and should get you a lot of the way there. – TessellatingHeckler Jul 04 '17 at 19:05

1 Answers1

0

This took me all morning but I finally got it to work!

For those who are interested in using powershell to clean up those large and unruly directories, your welcome :]

##########################
# 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++

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