VBScript to copy user defined no of row from source file into new file

Discussion in 'Visual Basic ( VB )' started by punit, Apr 11, 2010.

  1. punit

    punit New Member

    Apr 11, 2010
    Likes Received:
    Trophy Points:
    below is the script which reads all the lines of text file, and echo.

    Option Explicit
    Dim objFSO, strTextFile, strData, strLine, arrLines
    CONST ForReading = 1
    'name of the text file
    strTextFile = "INFORMATION_DATA_INFO1.csv"
    'Create a File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Open the text file - strData now contains the whole file
    strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll
    'Split the text file into lines
    arrLines = Split(strData,vbCrLf)
    'Step through the lines
    For Each strLine in arrLines
    wscript.echo strLine
    Set objFSO = Nothing

    Plese please please,
    can anybody modify the above script, to read user define no of rows, and copy that row into new text file with same name as source file on same location where source file is present
    i m using following syntex to run the above mention script from command line (windows),
    cscript "file location\script.vbs" (Above script)
    which is working perfectly fine,
    But what i want is, with above syntex now i will enter No.of raw which i wants to read, and please dont make this script hard code i.e i have to change name of source.file in to the script. which also i want user will pass with .vbs script, so the final syntex that i will enter in command line (windows)is as follows;
    cscript "Script_location\Script.vbs" "File_location\File_Name.txt" "Row_count"
    "Script_location\Script.vbs" = Our script.vbs location
    "File_location\File_Name.txt" = source file which user wants to read
    "Row_Count" = No of row of source.txt which user wants to read

    After running above line in command line the new text file which is created by the script which contain only user specified no. of rows on the same loacation where source file is present.
    ya and 1 last thing is, while running above script it should not give any popup on screen, new script should do its work quitly.
    Please i want this thing urgently, as i m new with vbscripting and i m not able to write vbscript on my own, need help please.......
    Last edited by a moderator: Apr 16, 2010

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice