I am writing a batch file for submiting helpdesk tickets. I need the script to see if the file that is going to be created already exists (%nameuser%) and if so then name the file that is going to be created %nameuser1% and consectutive after that 1,2,3,4,5 ect.
My code looks as follows:
echo. HelpDesk Program Written By PFC Torrey, Stephen 7:46 PM 1/4/2010
::maps network drive
echo. Mapping Network Drive
net use s: \10.10.4.69shared
::prompt for user name
echo "Who Is Submitting this Ticket?, (Last Name First Name NO SPACES )?"
set /p nameuser=
::makes dir off of user name prompt in mapped drive
:: prompt for unit
echo "What Unit do you belong to?"
set /p unit=
:: prompt for problem
echo "What are you having a problem with?, (Computer, Radio, BFT, Other)
set /p problem=
:: prompt for discription
echo "Please discribe the problem in detail,"
echo "including any steps needed to trigger the problem."
set /p discription=
:: prompt for building number
echo "What building number are you in?"
set /p buildingnumber=
::prompt for phone number
echo "Please provide a valid phone number, or extention"
set /p phonenumber=
echo. "Creating Ticket please stand-by"
echo. %unit% > %drive%%nameuser%.txt
echo. %nameuser% >>%drive%%nameuser%.txt
echo. %problem% >>%drive%%nameuser%.txt
echo. %discription% >>%drive%%nameuser%.txt
echo. %buildingnumber% >>%drive%%nameuser%.txt
echo. %phonenumber% >>%drive%%nameuser%.txt
::Prints IP Configuartion to Ticket
echo. Creating IP Configuration
ipconfig /all >> %drive%%nameuser%.txt
echo. "Your Ticket has been submitted, please stand-by for a S6 rep to contact you."
echo. "-PFC Torrey, Stephen R"
Any idea would be awesome.
Thanks in Advance
Here is one batch script that will find the latest directory called $usernameXXX.
# Script FindNextTicket.txt
var str username, dir ; var int count ; var bool found
while ( NOT($found) )
set $dir = "S:CAINhelptickets"+"/"+$username
set $dir = "S:CAINhelptickets"+"/"+$username+makestr(int($count))
if ( NOT ($fexists) )
set $found = true
echo "The correct directory path is " $dir
echo -e "DEBUG: Directory " $dir " already exists."
set $count = $count + 1
This batch script is in biterscripting. Save the script in file "C:/Scripts/FindNextTicket.txt"
Then add the following commands in your batch script.
"C:/biterscripting/biterscripting.exe" "C:/Scripts/FindNextTicket.txt" username("%nameuser%") -oo "output.txt"
Thanks to Richard.Williams
for this tip on the forum.