Computer Hope
Microsoft => Microsoft DOS => Topic started by: ddjedidd 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
-
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
-
You could replace this:
ECHO.%ACCOUNTNUM% | FIND /I "RS">Nul && ( goto RSAccount ) || ( goto NoRS )
With this
IF NOT "%accountnum:rs=%"=="%accountnum%" GOTO RSAccount