Computing.Net > Forums > Windows XP > Batch File Parsing a text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File Parsing a text file

Reply to Message Icon

Name: G14Y
Date: May 16, 2006 at 12:00:07 Pacific
OS: winxpsp2
CPU/Ram: 512
Comment:

Hi
I'm trying to create a batch file that will parse a text file and copy these files into the correct folders. The problem that I having is the file names and extension that I want the batch file to read from the text file, have the same type of extension but have different content and therefore belong in different folders. Can a batch file do this or do I need to look for another way of doing this?

Thanks

Example of the text file

Tables
run_member.sql
client_application.sql

Triggers
t_program_button.sql

Static_data
Description_types.sql



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: May 16, 2006 at 12:23:12 Pacific
Reply:

So this:

" Tables
run_member.sql
client_application.sql

Triggers
t_program_button.sql

Static_data
Description_types.sql"

is the contents of the file, right?

What's the task/question?


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 2
Name: CyberSlug
Date: May 16, 2006 at 14:19:11 Pacific
Reply:

Example code using the free scripting language AutoIt v3:

;For simplicity, assume that the section names (Tables, Triggers, Static_data) correspond to existing folder

FileChangedir("B:") ;paths relative to B: drive

$file = FileOpenDialog("Pick a file","","Text (*.txt)")
If @error Then Abort("No file selected")

$readHandle = FileOpen("example.txt", 0)
If @error Then Abort("Unable to open file")

$section = ""

; Read in lines of text until the EOF is reached
While 1
$line = FileReadLine($readHandle)
If @error = -1 Then ExitLoop
If $line = "" Then ContinueLoop ;skip blank lines

If $line = "Tables" Or $line = "Triggers" Or $line = "Static_data" Then
$section = $line
ContinueLoop
EndIf

;flag value of 1 means overwrite existing files
;You could replace .\ with absolute paths....
FileCopy(".\" & $line, ".\" & $section & "\", 1)
Wend

FileClose($file) ;this command is not strictly needed

Func Abort($description)
MsgBox(0x1000,"Quitting", $description)
Exit(1)
EndFunc


0

Response Number 3
Name: G14Y
Date: May 16, 2006 at 15:00:55 Pacific
Reply:

Thanks Cyberslug

Sorry M2 should have been more specific

The batch file should read each file name from each section in the text file and copy these files to there respective folders


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Batch File Parsing a text file

Batch file parsing a text file www.computing.net/answers/windows-xp/batch-file-parsing-a-text-file/174226.html

parsing through a text file using a batch www.computing.net/answers/windows-xp/parsing-through-a-text-file-using-a-batch-/180355.html

Batch file to edit text file www.computing.net/answers/windows-xp/batch-file-to-edit-text-file/156973.html