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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:26:22+00:00 2026-06-17T07:26:22+00:00

I have a script that renames files to dates entered by the user at

  • 0

I have a script that renames files to dates entered by the user at the keyboard- It’s very simple, just asks for the month, day, and year. As long as the user enters 2-digit values, it works well… the problem is that sometimes the user does not enter the leading 0, and then the whole thing falls apart. How do I make sure the leading 0 is included?
So far, here is what I have:

    $BatchDay = $(read-host "Enter Day of Month")
    if ($BatchDay -eq ''){$BatchDay = Get-Date -format dd}
    $BatchMonth = $(read-host "Enter Month of Year")
    if ($BatchMonth -eq ''){$BatchMonth = Get-Date -format MM}
    $BatchYear = $(read-host "Enter Year")
    if ($BatchYear -eq ''){$BatchYear = Get-Date -format yy}

Then it concatenates the numbers to build the filename:

    $Filename = "Customer--$BatchMonth-$BatchDay-$BatchYear($BatchNum).txt"

How do I force the variables to be two-digit, even when days and months are only one digit?

Thanks!

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

    You can just create your filename formating your vars :

    $a = ("{0:00}-{1:00}" -f 1,2)
    

    gives

    01-02
    

    in your case :

    $Filename = ("Customer--{0:00}-{1:00}-{2:00}({3:00}).txt" -f $BatchMonth,$BatchDay,$BatchYear,$BatchNum)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a groovy script that renames files that match a regex I launch
I have a script that renames files before uploading them to an FTP. First
I have following script that executes all the .reg files in the current directory.
i have this very simple download page to get an xml file. the script
1.Hi, I have a internal use only file upload script that uploads the files
I have a script which moves and renames files from an AS400 directory to
I have this script, that does several operations on some files, which then creates
I have a script that searches through a directory for files containing a particular
I'm making a CLI script that mass renames files, however I do not know
I have a PHP script that moves files out of a specific folder on

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.