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 8766569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:35:15+00:00 2026-06-13T16:35:15+00:00

I’ve got a folder that gets filled with a bunch of log files that

  • 0

I’ve got a folder that gets filled with a bunch of log files that need to be moved into sub-folders every so often. For example, I need to get the following files into the directories at the arrow.

SOME_FILE_341213.txt –> SMPROD
SOME_FILE_341242.txt –> SMPROD
OTHER_FILE_13423.log –> SSBRPRD
ALTER_FILE_13423.log –> SSBRPRD
geofile12321 –> REGIONPROD

I’ve seen lots of solutions that will parse out part of a file name and move it into a directory containing that parse of the file name. In my case, the destination directories will not really match up to a parsed part of the file names. I was thinking I could use a switch statement to match the first 4 or 5 letters to cases that would move files into the appropriate directories but I’m not sure that’s the most efficient way to go about it. I would have about 25 cases to match to. For files that didn’t match any case I would leave them where they are. Any advice?

  • 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-06-13T16:35:17+00:00Added an answer on June 13, 2026 at 4:35 pm

    I would go with the switch statement in a for-each loop. Something like this:

    $Files = Dir c:\test
    
    foreach ($file in $files) {
        switch ($file.ToString().Substring(0,2)) {
            "te" {Write-Host "te"; break}
            "li" {Write-Host "li"; break}
            "ts" {Write-Host "ts"; break}
    
        } #End switch
    } #End foreach
    

    On the substring(x,y) command, the overload is:

    1. x = starting character
    2. y = number of characters to pull

    Obviously replace the write-host with what you actually want to do. The switch statement can span multiple lines. Don’t forget the break at the end, so you don’t go through all 25 options for every file.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I

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.