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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:46:43+00:00 2026-05-26T07:46:43+00:00

I have never used Powershell (or VBScript) as I am new to IT-Admin and

  • 0

I have never used Powershell (or VBScript) as I am new to IT-Admin and would appreciate some guidance with renaming files.

On a daily basis, I will be downloading files useing Filezilla manually from a SFTP connection to a local directory filder called YYYYMMDD (although later, I will want to write an automated task that does this form me on a scheduled basis). What I would like to set up is some kind of task that when the files land into the distination directory, they get renamed.

For today’s download, I have the following files that I would like to rename:

Original Name                   Renamed Filename
wcm14444.csv.11.10.20_09.32     wcm14444_111020_0932.csv
wcm14444.csv.11.10.21_00.09     wcm14444_111021_0009.csv
wcm14444.pdf.11.10.20_09.32     wcm14444_111020_0932.pdf
wcm14444.pdf.11.10.21_00.10     wcm14444_111021_0010.pdf
wcm1cash.csv.11.10.21_00.56     wcm1cash_111021_0056.csv
wcm1money.csv.11.10.21_00.56    wcm1money_111021_0056.csv
wcm1opnpos.csv.11.10.21_00.56   wcm1opnpos_111021_0056.csv
wcm1trades.csv.11.10.21_00.56   wcm1trades_111021_0056.csv
wcm1_an.pdf.11.10.21_03.26      wcm1_an_111021_0326.pdf
wcm1_ds.pdf.11.10.21_00.22      wcm1_ds_111021_0022.pdf
wcm1_ep.csv.11.10.21_03.26      wcm1_ep_111021_0326.csv
wcm1_ms.pdf.11.10.21_03.26      wcm1_ms_111021_0326.pdf

You will notice in my renaming requirement:
1. The file extension appears in the middle of the filename and gets placed to the end.
2. I am replacing “.” with “” where they appear as date seperators. If its of any help, I am only expecting to receive file types of (“.csv”, “.pdf” , “.xls”) and where these appear within the filename, they get replaced with “_”.

Currently I would use Excel to perform the task, but this seems quite hard to deploy as a system task? This seems more of a task for Powershell.

If I am creating YYYYMMDD folders for example N:\SFTP\Provider1\YYYYMMDD, what would be the best way of automating the renaming of the files as the files are downloaded into each day’s YYYYMMDD (noting that on same days there may not be a folder created because there are no new files).
Many thanks and kind regards,
Bertie.


Thanks all for the help. More for the benefit of those stumbling accross this page. I have now created a Rename_SFTP.ps1 file at N:\SFTP\Provider1\ containing

$pattern = '^([^\.]+)\.(csv|xls|pdf)\.(\d{2})\.(\d{2})\.(\d{2})_(\d{2})\.(\d{2})'
$todayDate = Get-Date -Format "yyyyMMdd"

Get-ChildItem (".\" + $todayDate + "\") -Recurse | Foreach-Object{
    if($_.Name -match $pattern)
    {
        echo $NewName
        $NewName = "{0}_{1}{2}{3}_{4}{5}.{6}" -f $matches[1],$matches[3],$matches[4],$matches[5],$matches[6],$matches[7],$matches[2]
        Rename-Item (".\" + $todayDate + "\" + $_) -NewName $NewName
    }
}

I have then created a RunRenameTaskForToday.bat containing

powershell .\Rename_SFTP.ps1

At least this way, when I download the files manually, all I need to do is double click on a .bat file one level higher up and it will figure the right folder that needs the files to be renamed. All I need to do know is figure out a way to downlaod the SFTP stuff autonatically…

Thanks all.

  • 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-26T07:46:43+00:00Added an answer on May 26, 2026 at 7:46 am

    Here’s another way using a format string to create the new name. Each group of pattern characters surrounded in parenthesis denotes a part of the file name to be captured and is used later on in the $NewName to form the new file name:

    $pattern = '^([^\.]+)\.(csv|xls|pdf)\.(\d{2})\.(\d{2})\.(\d{2})_(\d{2})\.(\d{2})'
    
    
    Get-ChildItem D:\temp -Recurse | Foreach-Object{
        if($_.Name -match $pattern)
        {
            $NewName = "{0}_{1}{2}{3}_{4}{5}.{6}" -f $matches[1],$matches[3],$matches[4],$matches[5],$matches[6],$matches[7],$matches[2]
            Rename-Item $_ -NewName $NewName
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have never used DBIx::Class until today, so I'm completely new at it. I'm
I am new ASP.NET and I have never used a GridView or DataGrid, but
I've never used the Global Temporary Tables however I have some questions how they
I'm a database programmer, but I have never used data flow/diagram program. I would
I have never used SVN, but am familiar with some SM (source safe a
I have never used threads--never thought my code would benefit. However, I think threading
I have never used octal numbers in my code nor come across any code
i have never used LINQ in any of my projects , i have always
I have never used virtualization, and am trying to get up to speed. My
I have never used Perl, but I am really impressed by the ack ,

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.