#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2007
    Posts
    4
    Rep Power
    0

    Read line of text and create files


    Using Windows XP and Windows 7

    I would like to create files from each line of text reading from textfile.txt and put the files in a directory c:\myfiles\

    Hereís what I have
    The content of Textfile.txt file is as follow;

    Hello Joe
    Good morning
    Yesterday was the first
    Today the 2nd
    Tomorrow the 5th

    When I run the script I like to end up with;

    C:\myfiles\Hello Joe.txt
    C:\myfiles\Good morning.txt
    C:\myfiles\Yesterday was the first.txt
    C:\myfiles\Today the 2nd.txt
    C:\myfiles\Tomorrow the 5th .txt

    Thanks in advance..
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    193
    Rep Power
    328
    Sounds a bit like a homework... but google how to read text files, how to write text files and how to make a loop. Once you have put something together and if it doesn't work, place the code here together with possible error message(s) and somebody will definitely help you. But you have to be a bit more initiative than that, not sure if somebody here is willing to hand over the code or do your homework for you.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2007
    Posts
    4
    Rep Power
    0

    Smile


    Thanks for taking the time and feedback. No itís not a homework! LOL.. itís related to movie library Iím putting together and this is one part of it. I been experiment with batch files and command line.. the closest one I came across work partially but it was intended to work with existing files and not to create one from scratch!

    I'm using a batch file (file.bat)

    This is the command line in the batch file..

    for /f "delims=" %%i in (filelist.txt) do echo D|xcopy "%%i" "c:\myfiles\%%i" /i /Z /y


    This is what's happening when I run the batch file...


    C:\myfiles>files.bat

    C:\myfiles>for /F "delims=" %i in (filelist.txt) do echo D | xcopy "%i" "c:\myfiles\%i" /i /Z /y

    C:\myfiles>echo D | xcopy "Hello Joe" "c:\myfiles\Hello Joe" /i /Z /y
    File not found - Hello Joe
    0 File(s) copied

    C:\myfiles>echo D | xcopy "Good morning" "c:\myfiles\Good morning" /i /Z /y
    File not found - Good morning
    0 File(s) copied

    C:\myfiles>echo D | xcopy "Yesterday was the first" "c:\myfiles\Yesterday was the first" /i /Z /y
    File not found - Yesterday was the first
    0 File(s) copied

    C:\myfiles>echo D | xcopy "Today the 2nd" "c:\myfiles\Today the 2nd" /i /Z /y
    File not found - Today the 2nd
    0 File(s) copied

    C:\myfiles>echo D | xcopy "Tomorrow the 5th" "c:\myfiles\Tomorrow the 5th" /i /Z /y
    File not found - Tomorrow the 5th
    0 File(s) copied

    C:\myfiles>

    Hope this helps...
  6. #4
  7. No Profile Picture
    Stumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,409
    Rep Power
    4538
    If there are spaces in the file name after it's expanded by your batch file, you need quotes around that filename. To do this you'd normally embed quotes by putting double quotes inside the quoted string. That's how it would work with vbscript, anyway, I'm not sure with batch files, this is a VB forum.
    ======
    Doug G
    ======
    It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2007
    Posts
    4
    Rep Power
    0
    Doug, I can live with VB script as long as the end results is right!
    Thank you
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    23
    Rep Power
    0

    dos vb scheebee


    Originally Posted by sunnie_joe
    Doug, I can live with VB script as long as the end results is right!
    Thank you
    I like your attitude, anything that works will do...

    a post after yours asks about capturing output from cmd

    if you call your batch file you will be creating a number of calls to the system.

    simply add >>filename.bat when calling your batch file and the result will show you exactly what you are creating without the problems associated with the creation.

    this way you can build a better batchfile from the output file and debug your original batch file in the process

    I often use a batch file and textfile combination to create the batch file that will actually do the work.

    in light of this being a vb forum a vb thing can be supplied if needed


    bill stewart - here to talk

IMN logo majestic logo threadwatch logo seochat tools logo