|
Answer» Hello everyone!
I used the search function and found nothing on this question at hand.
I am WRITING a batchfile for a professor of mine at dunwoody. The purpose of the bat is to take a data file, containing students emails/Firstname Lastname, and make directories for each student in a parent directory. But the PROBLEM is the data file format is really gross. Its being taken from our intranetwork site, which displays the text as follows.
[emailprotected](James Smith);[emailprotected](James Smith);[emailprotected](James Smith);[emailprotected](James Smith);
[emailprotected](James Smith);[emailprotected](James Smith);
[emailprotected](James Smith);[emailprotected](James Smith);[emailprotected](James Smith);[emailprotected](James Smith);
and for the script to work the "[emailprotected](James Smith);" needs to be on separate lines like: [emailprotected](James Smith); [emailprotected](James Smith);
so here's the question -- how do you parse/format the data file within the batch file? Do i need the batch to call a vbs? you can email me at @[emailprotected] or pm me on here.
All help is appreciated.
Thank you The_Valkyrie so 34+ views and no help................... Why don't you post the batch file so that someone can look at it for you?::!--------------------------------------------------------------------------! ::!--------------------------------------------------------------------------! ::Batchfile : allomk ::Purpose : Create Firstname_Lastname folders of students for Teacher. ::OS tested : WinXp ::Created by : Ben Jorgenson [emailprotected] ::Adopted by : Brian Carlson ::Revised : ::Version : v1.1 ::!--------------------------------------------------------------------------! ::!--------------------------------------------------------------------------! @echo off set /p course="What's the Course Number? " echo. set /p section="What's the Course Section Number? " if exist C:\test\CNTS%course%-%section% ( echo Making the Student's Folders..... ) else ( Echo Making the Course\Section Folder..... mkdir C:\test\CNTS%course%-%section% ) if %section%==01 goto section1 if %section%==02 goto section2 goto :eof pause :section1 for /f "tokens=1-3 delims=() " %%a in (C:\Studentnames\student_name.txt) do @mkdir "C:\test\CNTS%course%-01\%%b_%%c" exit /b
:section2 for /f "tokens=1-3 delims=() " %%a in (C:\Studentnames\student_name.txt) do @mkdir "C:\test\CNTS%course%-02\%%b_%%c" exit /b
:students :: Use the data list for the student names Echo its workign muahahaha! exit /b
But the bat works, i would like to know if the bat can parse data files.I'm not UNDERSTANDING the question. The batch file does not SEEM to match your original post.
Quote [emailprotected](James Smith);[emailprotected](James Smith);[emailprotected](James Smith);[emailprotected](James Smith);
[emailprotected](James Smith);[emailprotected](James Smith);
[emailprotected](James Smith);[emailprotected](James Smith);[emailprotected](James Smith);[emailprotected](James Smith);
You can use this little script to extract the student names from your data file: (just don't tell me all the students are named James Smith)
Code: [Select]Const ForReading = 1 Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("C:\temp\ch.txt", ForReading) 'Change input file label Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True objRegEx.Pattern = "\(+[A-Za-z ]+\);"
strSearchString = objFile.ReadAll objFile.Close
Set objFile = objFSO.OpenTextFile("c:\temp\Test.txt", ForWriting, True) 'Change output file label Set colMatches = objRegEx.Execute(strSearchString) If colMatches.Count > 0 Then For Each strMatch in colMatches objFile.Write Mid(strMatch.Value, 2, Len(strMatch.Value)-3) & vbCrLf Next End If objFile.Close
If you need the email address, the regex pattern can be tweaked. Batch code has the findstr command but the regex options are limited although the one in the script is about as simple as they come. Save the script with a vbs extension and run from either the command prompt or within a batch file as: cscript //nologo scriptname.vbs
Good luck. Quote from: The_Valkyrie on APRIL 29, 2010, 06:59:01 AMso 34+ views and no help...................
This kind of post is, in general, a bad idea.Quote from: Sidewinder on April 29, 2010, 11:15:24 AMI'm not understanding the question. The batch file does not seem to match your original post.
The bat has been tweaked out of boredom, but the original script is: for /f "tokens=1-3 delims=() usebackq" %%a in ("%userprofile%\Desktop\student_name.txt") do @mkdir C:\test\%%b_%%c
This allowed me to take the formatted file and create the folders. But thank you tons Sidewinder. (haha and no, all the students are not named "James Smith")
|