Author Posts

August 28, 2015 at 10:52 pm

I can run this command
Get-ChildItem C:\Users\Admin\Downloads | Select-Object Extension | % {New-Item -Type Directory -path $_.Extension}

This drops my new folders into C:\
I would like to have them drop into another folder
like to C:\Users\Admin\Documents

Any tips?

The end result I am attempting to make is a quick Script to sort my documents per file type.
Then again per date created.

August 29, 2015 at 2:32 am

By default, it will put it wherever the current location is set. You can either use a push-location or set-location for the scope of the script or use its name specifically as below.

$root = "C:\Users\Admin\Documents"
Get-ChildItem C:\Users\Admin\Downloads | 
    Select-Object Extension | 
    foreach {New-Item -Type Directory -Path $(Join-Path $root $_.Extension)}

Also, in the future, when posting code you'd like others to review, please avoid single-character aliases like ? or %.

August 29, 2015 at 9:11 am

Thanks again for the help Bob McCoy.
The data conversion script you helped me with did exactly what I needed!

How do you get that neat little script box?

August 29, 2015 at 10:36 am

Guess I screwed that up. At the bottom of the text input box you will see allowed tags. Use the pre and /pre tags to wrap your code.

August 29, 2015 at 10:44 am

Function Create-ExtensionFolder {
Param(
$EndPath = "C:\Users\Admin\Documents",
$StartPath = "C:\Users\Admin\Downloads"
)
$Filter = Get-ChildItem -Path $StartPath | Select-Object Extension

Get-ChildItem $StartPath | 
    Select-Object Extension | 
        foreach {
            New-Item -Type Directory -Path $(Join-Path $EndPath $_.Extension)
                }
}

August 29, 2015 at 10:45 am

function Copy-ToExtension {
param(
$EndPath = "C:\Users\Admin\Documents",
$StartPath = "C:\Users\Admin\Downloads"
)
$ExtList = Get-ChildItem -Path $StartPath | Select-Object Extension
$FilterFiles = Get-ChildItem $StartPath -Filter *$ExtList -Recurse

foreach ($file in $FilterFiles)
        {
        $Ext = $file.Extension
        $EndPathExt = "$EndPath\$Ext"
        Copy-Item -Path $file.FullName -Destination $EndPathExt
        }
}

August 29, 2015 at 10:47 am

Course I just noticed after asking that question below Reply to Creating Folders
it saids
Enclose code blocks in

 and 

to format it
I made 2 functions
One to create my extension folders
and
the other to sort my documents for me.
I use the Copy-Item because I am testing and do not want to move files and loose files
I think the final version will be Move-Item to keep from massive archives of copys

August 30, 2015 at 12:29 pm

The other thing you can do is use the -WhatIf switch for the Move-Item cmdlet.