General discussion

  • Creator
    Topic
  • #4257664

    Batch Script – Create Directory, User Prompted

    by wheeler.bradley ·

    Tags: 

    I have the following batch script which creates a new directory after asking user to enter the desired folder name:


    @echo
    off
    set /p “folder=Enter the folder name to be created: ”
    mkdir “%folder%\A-”
    mkdir “%folder%\Investigation”
    mkdir “%folder%\Photos”

    However, I’d like multiple user prompts to force the user in the naming convention of the folder for consistency. Example, instead of only one question asking the folder name: “2024-08-22” and then the folder is created 2024-08-22. We would prefer multiple prompts such as:
    “Please enter 4 digit year” user would only enter 2024
    “Please enter 2 digit month” user would only enter 08
    “Please enter 2 digit day” user would enter 22

    The folder would then be named appropriately 2024-08-22
    Suggestions?

You are posting a reply to: Batch Script – Create Directory, User Prompted

The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our Community FAQs for details. All submitted content is subject to our Terms of Use.

All Comments

  • Author
    Replies
    • #4257697
      Avatar photo

      Reply To: Batch Script – Create Directory, User Prompted

      by kees_b ·

      In reply to Batch Script – Create Directory, User Prompted

      Instead of asking for %folder% ask for %year%, %month% and %day%
      Then in stead of creating %folder% create %year%-%month%-%day%

      But it would be preferable to write a vb-script, so you can check that they don’t enter July or 7 or 13, only valid month numbers. And the folder shouldn’t yet exist.

    • #4257764
      Avatar photo

      Since you want to do this yourself, why not use a robot?

      by rproffitt ·

      In reply to Batch Script – Create Directory, User Prompted

      This is exactly something I’d try on ChatGPT.

    • #4260477

      my opinion

      by basika0911 ·

      In reply to Batch Script – Create Directory, User Prompted

      You can modify your batch script to include separate prompts for year, month, and day, then combine them to create the folder name. Here’s an updated version:

      batch

      @echo
      off
      set /p “year=Please enter 4 digit year: ”
      set /p “month=Please enter 2 digit month: ”
      set /p “day=Please enter 2 digit day: ”
      set “folder=%year%-%month%-%day%

      mkdir “%folder%\A-”
      mkdir “%folder%\Investigation”
      mkdir “%folder%\Photos”

      echo Folder created: %folder%
      pause
      This will prompt the user to enter each part separately and then create the folder with the correct format (e.g., 2024-08-22).

Viewing 2 reply threads