Append first line of dir files to output file

As a newbie I am struggling to write a VBS script and would appreciate some help. I have searched through previous queries but couldn't find anything to match this:

I have directory with a fair number of files in it and wish to write a VBS script which will go through all the files in the directory and copy the first line of each of the files and append each first line to a list in an output file.

I have made a start but am at a loss how to proceed to write the info to the output file

Any help or script would be greatly appreciated.

JuniperGreen

"Script:

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set folder = objFSO.GetFolder("c:\library\")
Set outfile = objFSO.CreateTextFile("c:\library2\Reference.txt")
for each file in folder.Files
Set testfile = objFSO.OpenTextFile(file.path, ForReading)
Do While Not testfile.AtEndOfStream

StrLine = testfile.ReadLine
Loop
Testfile.close
Set testfile = nothing
Next
Outfile.close"
 

My Computer

Hello JuniperGreen and welcome to the forums :party:

Two questions:

1) Can I do it in batch instead?
2) Are they all text files?

Tom
 

My Computer

System One

  • Manufacturer/Model
    Build #1
    CPU
    Intel Core i7 3770K @4.4GHz
    Motherboard
    ASUS P8Z77-V PRO
    Memory
    Corsair Vengeance 2x4GB DDR3 1600MHz Low Profile (White)
    Graphics card(s)
    Gigabyte Radeon HD 7850 (2GB GDDR5)
    Sound Card
    Integrated on motherboard
    Monitor(s) Displays
    23" LG LCD/LED IPS
    Screen Resolution
    1920*1080
    Hard Drives
    Samsung EVO 128GB SSD Seagate Barracuda 2TB 7200rpm 2x500GB Seagate FreeAgent 5400rpm
    PSU
    Corsair TX650W V2 (80+ Bronze)
    Case
    NZXT Phantom 410
    Cooling
    Corsair H100 Water Cooler, 1x140mm and 1x120mm stock fans
    Mouse
    Microsoft Desktop 2000 Wireless Mouse
    Keyboard
    Microsoft Desktop 2000 Wireless Keyboard
    Internet Speed
    95 Mb/s Download 70 Mb/s Upload
Hi Tom,

While I would really prefer VBS, I would be grateful for a batch file version although it is a long time since I used batch files. Only text files are involved.

Thank you
 
Last edited:

My Computer

Back
Top