Rearrange files in Desktop with their extensions

We may have lot of files in desktop some times 20,40 and go on. Too many word doc, excel, Jpeg and screenshot, text files. we would have face a situation where we will be searing a file in desktop one by one. So thought of having a folder for each extension. This script will create a folder with extension name and move those files with respective folders.



$DesktopPath = [Environment]::GetFolderPath("Desktop")

$Dir = get-childitem $DesktopPath -file

$Dir | foreach-Object{


    $extname= $_.extension




    CreateFolder ($extFolder)

    MoveFile ($Fname,$extFolder)


Function CreateFolder ($extFolder){

    If(!(test-path $extFolder))


        New-Item -ItemType Directory -Force -Path $extFolder



Function MoveFile ($source,$destination) {


  Move-item -path $Fname -Destination $extFolder




Here is the output


Same script has been hosted in GitHub