Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6056769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:24:50+00:00 2026-05-23T08:24:50+00:00

I have this script which runs periodically to collect desktop files and organizes them

  • 0

I have this script which runs periodically to collect desktop files and organizes them by the file type into a single folder on backup drive.

function get-destbytype($ext) 
{
    switch ($ext)
    {
        { $ext -match '(jpg|png|gif|bmp)'} { "images" }
        { $ext -match '(divx|mpeg|avi)'} { "videos" }
        { $ext -match '(cs|js|java|py|class|vbs|jsp)'} { "code" }
        { $ext -match '(sql|ps1|pl|py)'} { "scripts" }
        { $ext -match '(zip|7z|rar)'} { "compressed" }
        { $ext -match '(ppt|pptx|doc|docx|pdf)'} { "documents" }
        { $ext -match '(csv|xls|xlsx)'} { "spreadsheets" }
        { $ext -match '(exe|dll|jar|ear|bat|cmd)'} { "executables" }
        { $ext -match '(txt|log)'} { "text" }
        { $ext -match '(msg|htm|html|lnk)'} { "miscellaneous" }
        { $ext -match '(properties|xml|ini)'} { "config" }
        default {"$ext" }
    }
}

$dirtyfolder = "C:\Documents and Settings\user\Desktop\"
$org = "$nas\Desktop\ORG"

ls $dirtyfolder/* | ? {!$_.PSIsContainer} | %{
  $dest = "$($org)\$(get-destbytype $_.extension)"
  if (! (Test-Path -path $dest ) ) 
  {
    write-host "creating $dest"
    new-item $dest -type directory
  }
  mv -path $_ -destination $dest 
}

The script was tested thoroughly and seems to run fine in most cases I could imagine. Recently when .csv files were encountered for the first time, they were moved into a new folder by the name

code spreadsheets.

This is obviously because the .cs files are supposed to go to the code folder and the .csv files to the spreadsheets folder, and the script does not distinguish between .cs and .csv.

How do I modify the script to not do this?

Also what can be done to exclude desktop shortcuts with extension .lnk?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:24:51+00:00Added an answer on May 23, 2026 at 8:24 am

    Try using a more specific regular expression. Just add $ signs at the end of your expressions. The $ sign indicates end of line or in your case end of string.

    It would look like this:

    { $ext -match '(jpg|png|gif|bmp)$'} { "images" }
    

    You can easily test this by opening powershell and typing:

    "abc.csv" -match '(cs|xls)$'
    

    This will result in False.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script, that does several operations on some files, which then creates
I have this script which runs well in Python 2.7 but not in 2.6:
I have made a batch script which runs a Python application. This batch script
I have a script which runs through a database table and downloads a file
I have a python script which runs and generates a version-file. I use the
I have a php script which runs on my ubunutu server. this script runs
I have a PHP script which runs a MySQL query. $query = INSERT INTO
I have this script: $.each($(this)[0].files, function(i, file){ if (input.files && input.files[0]) { var reader
I have this script which basically toggles a bgColor class on and off so
I have this script which simply kills an app KEY_NAME=/some/path kill `ps -ef |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.