Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File to create, move folder name based on user input  (Read 4141 times)

0 Members and 1 Guest are viewing this topic.

ddjedidd

    Topic Starter


    Greenhorn

    • Experience: Beginner
    • OS: Windows 7
    Batch File to create, move folder name based on user input
    « on: March 18, 2017, 08:10:23 AM »
    I'm looking to create a batch file that will create, move folder name based on user input.

    Example: What is your account? (user inputs an account name like 123RS456 or 78-910)
    Test 1: The user inputs 123RS456
    Test 2: The user inputs 78-910
    Test 3: The user inputs 123-4567

    That batch file creates folder based on characters in the account name and moves that folder.

    Result for Test 1: C:\Accounts\Accounts_with_RS\456_123EA456 -the batch takes every character after 'RS' and renames it before an underscore

    Result for Test 2: C:\Accounts\Accounts_without_RS\78910 -the batch will remove the "-" dash.

    Result for Test 3: C:\Accounts\Accounts_without_RS\1234567 -the batch will remove the "-" dash.

    I've gotten as far as having the user input into a .txt file thinking I could rename it, and make a directory from it, but that is as far as I can get. Any help is appreciated

    This is what I have so far,

    @echo off
    title intro color 1f
    echo You will have to type the account name below
    set /p FILENAME="What is your account? "
    echo %FILENAME% > temp.txt
    REN C:\Accounts\temp.txt %FILENAME%.txt   - This does not work

    ddjedidd

      Topic Starter


      Greenhorn

      • Experience: Beginner
      • OS: Windows 7
      Re: Batch File to create, move folder name based on user input
      « Reply #1 on: March 19, 2017, 08:52:20 AM »
      I figured it out... See Below

      @echo off
      title intro
      color 1f
      set /p ACCOUNTNUM="What is your account?"
      ECHO.%ACCOUNTNUM% | FIND /I "RS">Nul && ( goto RSAccount ) || ( goto NoRS )

      :NoRS
      set FILEPREFIX=%ACCOUNTNUM:~0,2%
      set FILESUFFIX=%ACCOUNTNUM:~3%
      md %FILEPREFIX%%FILESUFFIX%
      move "C:\Accounts\%FILEPREFIX%%FILESUFFIX%" "C:\Accounts\Accounts_without_RS\%FILEPREFIX%%FILESUFFIX%"
      pause
      exit

      :RSAccount
      set FILEPREFIX=%ACCOUNTNUM:~5,3%
      set FILESUFFIX=%ACCOUNTNUM:~5%
      md %FILEPREFIX%"_"%ACCOUNTNUM%
      move "C:\Accounts\%FILEPREFIX%_%ACCOUNTNUM%" "C:\Accounts\Accounts_with_RS\%FILEPREFIX%_%ACCOUNTNUM%"
      pause
      exit

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: Batch File to create, move folder name based on user input
      « Reply #2 on: March 19, 2017, 10:56:59 PM »
      You could replace this:
      Code: [Select]
      ECHO.%ACCOUNTNUM% | FIND /I "RS">Nul && ( goto RSAccount ) || ( goto NoRS )With this
      Code: [Select]
      IF NOT "%accountnum:rs=%"=="%accountnum%" GOTO RSAccount