/build/static/layout/Breadcrumb_cap_w.png

Rearrange Desktop files with file extension

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.

Script:

 

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

$Dir = get-childitem $DesktopPath -file

$Dir | foreach-Object{

  

    $extname= $_.extension

    $Dname=$_.DirectoryName

    $Fname=$_.FullName

    $extFolder=$Dname+"\"+$extname

    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

UvUhXI.png


Same script has been hosted in GitHub


Comments

This post is locked
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ