Page 1 of 1

Posted: Fri May 17, 2002 11:24 am
by BackupUser
Restored from previous forum. Originally posted by willinyork.

hi (again!)

In my program I write a textfile containing a line of filenames seperated by one space between each filename. I then want to go through the file and output each filename to an indiviual textfile.

the code I have is like this:

position=0
filenumber=1

ReadFile(1,"c:\aiff2vagscript.txt")
FileSeek(position)
wavfiles$=ReadString()
CloseFile(1)
;above to read the contents of the file into a string called wavfiles$

While filenumber<(num+1)

positionofaif=FindString(wavfiles$,".aif",position)

newwavfiles$=Mid(wavfiles$,position,positionofaif+4)

CreateFile(2,"c:\testoutput"+Str(filenumber)+".txt")
WriteString(newwavfiles$)
CloseFile(2)

newwavefiles$=""

position=positionofaif+5

filenumber=filenumber+1
Wend

It SEEMS to work fine - however, if wavfiles$ = "file1.aif file2.aif file3.aif " then the three indiviual textfiles created are ALMOST correct - the first one contains just "file1.aif" the thrid one contains just "file3.aif" but the second one contains "file2.aif file3.aif" and I can't work out why it does this! Also, it seems to mess up if I use more filenames in the wavfiles$ string. Any advice appreciated! Thank you :) (You lot are very good to me!)

Posted: Fri May 17, 2002 2:43 pm
by BackupUser
Restored from previous forum. Originally posted by merendo.

Um, I would do this quite differently. I would read the ASCII-Value of the strings, and then look for a space-figure. Something like this probably:

Code: Select all

if openfile(0,filename$)
  ascii = readbyte()
  while ascii  32
   word$ + chr(ascii)
    ascii = readbyte()
  wend
endif
We always need to hear both sides of the story (by Phil Collins)

Posted: Sat May 18, 2002 1:19 pm
by BackupUser
Restored from previous forum. Originally posted by willinyork.
Um, I would do this quite differently. I would read the ASCII-Value of the strings, and then look for a space-figure. Something like this probably:

Code: Select all

if openfile(0,filename$)
  ascii = readbyte()
  while ascii  32
   word$ + chr(ascii)
    ascii = readbyte()
  wend
endif
Hi again

Thanks for your help, but still I cannot fully understand it (and cannot get it to work). I have modifield my code like this:

While filenumber 32
word$ + Chr(ascii)
ascii = ReadByte()
Wend
position=Loc()
CreateFile(3,"c:\newfile"+Str(filenumber)+".txt")
WriteString(word$)
CloseFile(3)
EndIf
CloseFile(0)
Wend

filenumber=filenumber+1
Wend

Any ideas what I am doing wrong?

Thank you again!

Posted: Sat May 18, 2002 2:02 pm
by BackupUser
Restored from previous forum. Originally posted by fweil.

Maybe this one will help you ... just let me know it it corresponds to your need. i just took care that :

- if you have several lines in your input file (aiff2vagscript.txt) the code can process them.
- no file extension is tagged, just spaces as file names separator.

filenumber=0
If ReadFile(1,"c:\aiff2vagscript.txt")
Repeat
UseFile(1)
a$=StripLead(StripTrail(ReadString()))
Quit = 0
While Quit = 0
filenumber = filenumber + 1
iu = FindString(a$, " ", 1)
If iu = 0
Quit = 1
If CreateFile(2, "c:\textoutput" + Str(filenumber) + ".txt")
WriteString(a$)
EndIf
CloseFile(2)
Else
If CreateFile(2, "c:\textoutput" + Str(filenumber) + ".txt")
WriteString(Mid(a$, 1, FindString(a$, " ", 1)))
CloseFile(2)
EndIf
a$ = StripLead(StripTrail(Mid(a$, iu, Len(a$) -iu +1)))
EndIf
Wend
Until Eof(1)
CloseFile(1)
EndIf

End


Enjoy and have fun ...

Francois Weil
14, rue Douer
F64100 Bayonne

Posted: Sat May 18, 2002 2:33 pm
by BackupUser
Restored from previous forum. Originally posted by willinyork.

It works perfectly :)

THank you for your help Merendo and Francois!

Will