Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.sqlTriggers
t_program_button.sqlStatic_data
Description_types.sql

So this:
" Tables
run_member.sql
client_application.sqlTriggers
t_program_button.sqlStatic_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

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)
WendFileClose($file) ;this command is not strictly needed
Func Abort($description)
MsgBox(0x1000,"Quitting", $description)
Exit(1)
EndFunc

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

![]() |
![]() |
![]() |

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