# Solved: script question, suggestions needed...



## slafta (Aug 30, 2008)

I am writting some code to parse a directory contents into a text file, how ever here is my problem, since customer can modify to directories there are no static names. I was looking a vbs script solution to search a line with a text file and delete all text to the left of the '\' also this would have to be nested since each line could have multiple subdirectories, any ideas would be appreciated.


Thanks again for any input.


Modifed:
If I could find a way to read a text file, save the line into a string variable called current_line and then execute this segment and then write the modified current_line back into the original file at the same point.

here is the last code before i got stuck:::



fspec="list.txt"
set fso=createobject("scripting.filesystemobject")
set ots=fso.opentextfile(fspec)
do while not ots.atendofstream
s=ots.readline
'do thing with the info 
dim Result
Result = InStrRev(s, "\") 
s = Mid(s,(result+1))
ots.Write(s) 'problemed line thus far 
'(10, 6) Microsoft VBScript runtime error: Bad file mode
loop
ots.close
set ots=nothing
set fso=nothing



this would work, thanks for your assistance...


----------



## slafta (Aug 30, 2008)

Dim ArgObj, var1, var2 
Set ArgObj = WScript.Arguments 

'First parameter
var1 = ArgObj(0) 
'Second parameter
var2 = ArgObj(1) 
wscript.echo("Input Filename=" & var1 & " Output Filename=" 

& var2)

set fso=createobject("scripting.filesystemobject")

'OpenTextFile Parameters:
'-Filename
'-The 2 is for writing... 1 is reading and 8 is appending
'-The "True" is to create if not already there.

set input_file=fso.opentextfile(var1)
set output_file=fso.opentextfile(var2, 2, True)

do while not input_file.AtEndOfStream
s=input_file.readline
'ECHO FOR DEBUGGING ONLY---->wscript.echo(s)
'do thing with the info 
dim Result
Result = InStrRev(s, "\") 
'ECHO FOR DEBUGGING ONLY---->wscript.echo(Result)
s = Mid(s,(result+1))
'ECHO FOR DEBUGGING ONLY---->wscript.echo(s)
output_file.Write(s) 
output_file.Write(vbCrLf)
loop
input_file.close
set input_file=nothing
set fso=nothing


----------

