Vbscript to copy user defined number of row in new file

  • 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

    Next

    'Cleanup

    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"

    Where:-

    "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.......

  • Is this for an SSIS Package?

    Why not use VB.Net in the Script task?

    There are numerous examples on the File System Object that can be found on Goggle.

    I think I know what you want but you may want to restate you question and perhaps I can point you in the right direction.

    Regards,

    Welsh

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Thanks 4 ur suggetion Welsh,

    But i want this 4 personal use in my computer, actually i what i want to do is,

    If i'll get the 1st raw of .csv file which is Header row in my case, so than i want to make Mysql table with that column name,

    2nd reson for is that my source file which is .csv file is not static file. The no. of column in the file is is going to change, so if i get 1st row of any given file than i will write 1 script in Mysql which create table with that column names.

    3rd reason is, i dont want to use any readymaid tool available, which makes table in mysql database from given .csv file.

    4th and final reason is in windows we dont have much command to play with text files like linux(Eg:- cat File_name.csv -1). so only option left is .vbscripts with wich i m bit familier.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply