2

I'm using the following VBS script to delete the first n number for line from a file:

strInputFile = "*Filename.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
If Not objInputFile.AtEndOfStream Then
      objInputFile.SkipLine
Else
      WScript.Quit
End If
strContents = ""
While Not objInputFile.AtEndOfStream
      If strContents = "" Then
            strContents = objInputFile.ReadLine
      Else
            strContents = strContents & VbCrLf & objInputFile.ReadLine
      End If
Wend
objInputFile.Close
Set objInputFile = Nothing

Set objOutputFile = objFSO.CreateTextFile(strInputFile, True)
objOutputFile.Write strContents
objOutputFile.Close
Set objOutputFile = Nothing
Set objFSO = Nothing

How do I change the code so that instead of a constant input file it will be an argument when I start the program via CMD?

0

2 Answers 2

2

Have a look at wscript.arguments which provides access to the command line used to start the script.

if (wscript.arguments.count <> 1) then
    wscript.echo "Usage: dl2unc <drive-letter-path>"
    wscript.quit 1
end if

s = wscript.arguments.Item(0)
Sign up to request clarification or add additional context in comments.

Comments

0

change

strInputFile = "*filename.txt" 

to

strInputFile = WScript.Arguments(0)

and the first arg would be the file name.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.