Need to figure out how to do simple text edit macro program

Discussion in 'OT Technology' started by cassetti, Jul 7, 2005.

  1. cassetti

    cassetti New Member

    Joined:
    Nov 30, 2003
    Messages:
    252
    Likes Received:
    0
    Location:
    delaware
    I am trying to come up with a way to make my life easier at work (who doesn't)

    We have an online store - where we upload data every day - the file is exported from our database to a tab delimited file.

    From there - i have to open the file up - and put in a simple line of text with the lables of each colum - with tabs between them.

    It is so annoying - i am looknig for a way to create a simple executable dos program - that will take the program - when dragged into it (or ran as part of the exportation of the database) - to just insert a paragraph return - and insert one line of text into the top of the file.

    My experiance with C++ is very very limited - i have done creation of text tiles and even a simple database program within c++ for a unix shell in an advanced programming course at my college -b ut that was over a year ago - i'm not able to come up with anything now to do what i want.


    anyone got any clues to hwo - or suggest a simple program that will allow me to create a single executable file that will edit whatever text file that it opens -a nd put one simple line of text into it every time????

    thanks guys!
     
  2. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    If it's the same line of text everytime...

    Stick the line of text into a file called top.txt

    Then create a batchfile (text file but saved as a .bat extension):

    del final.txt
    copy top.txt final.txt
    type %1 >> final.txt

    That's it. Put that all into the same directory. Final.txt is the final product. Drag and drop the original file onto the batch file, or run from the command line: insert.bat someoutputfile.txt

    I could even write the ftp script to upload it if you wanted ;)

    BTW, the export portion of the database should actually have an option to export the field names as well.
     
  3. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,446
    Likes Received:
    12
    Under unix or ActiveState perl on this windows machine, this would be cake. But here's my simple attempt under dos batch.

    @echo off
    echo Name Price Date Field Whatever > title_temp.txt
    type %1 >> title_temp.txt
    del %1
    rename title_temp.txt %1

    This very limited on what it can do. It can only do one file at a time, you can't drag and drop into the bat, and it has to be local to where the ascii files are. I haven't created a batch file in the longest time. Maybe others will know how to tweak or know a better way.
     
  4. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    You can drag and drop into batch files ;)
     
  5. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,446
    Likes Received:
    12
    Not my batch...
     
  6. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Sure you can.
     
  7. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,446
    Likes Received:
    12
    I'm not here to argue about the functionality of dos batch files. I'm not jollygre.

    The batch file I wrote deletes the file you drag into it PERIOD. Go try it out for yourself.
     
  8. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    The problem isn't that it deletes it, it doesn't rename it properly, thus leaving you with no solution.
     
  9. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,446
    Likes Received:
    12
    Then how come it works if I just run

    test.bat filename.txt

    at the command line?

    If it doesn't rename it properly, then the title_temp.txt should reside, which it does not.

    What's the difference in stdin between cli and dragging it in.
     
  10. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    if you run it in the command line, you are in the directory where you created the batchfile, if you drag and drop the file, you start working in your my documents directory. IF you open it open, you should see your temp file.
     
  11. cassetti

    cassetti New Member

    Joined:
    Nov 30, 2003
    Messages:
    252
    Likes Received:
    0
    Location:
    delaware
    lol - thats awesome - i knew i could do it with a batch - just havn't done any dos work in so long
     
  12. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,446
    Likes Received:
    12
    Nope, I don't see anything in "My Documents" directory. I also checked the temp directories and do not see in there either. A search on my disks on this pc shows nothing. Also, all txt files created today are not from my test txt files if the batch decided to rename it to some obscure file name.
     
  13. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Not sure where it would be, if you open up the command prompt, whatever directory it starts off in should be there. Anyway, that's why it doesn't work, the batchfile is not running in the same directory. Just stick a pause command at the end of the batch file to see what I mean.
     
  14. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    I think I might see the problem - the rename command can't move files from one directory to another. Change the rename command to move and it should work.
     
  15. cassetti

    cassetti New Member

    Joined:
    Nov 30, 2003
    Messages:
    252
    Likes Received:
    0
    Location:
    delaware
    Well guys- i came up with using your suggestions - i found a great way to do it

    @echo off
    copy %1 tempfile.txt
    del %1
    type top.txt >> %1
    type tempfile.txt >> %1
    del tempfile.txt

    That is so simple - i must say.

    thanks a LOT for your help guys!
     
  16. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    That's great. You could change it to this if you wanted to:

    @echo off
    copy %1 tempfile.txt
    type top.txt > %1
    type tempfile.txt >> %1
    del tempfile.txt
     
  17. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,446
    Likes Received:
    12
    I see.
     
  18. cassetti

    cassetti New Member

    Joined:
    Nov 30, 2003
    Messages:
    252
    Likes Received:
    0
    Location:
    delaware
    Ok guys - well it seems my boss is too lazy to put the two batch files on the folder on the server with the database.

    Does anyone here know of where i can download a free simple c++ compiler to compile a dos based program for doing what i want.

    I have a good 60% or 70% of what i need to know - to create a simple program in c++ to do what i want.

    I used to have a few books on teach-yourself-c++ at my old house - that came with cd's that included dos based compilers - but i don't anymore.

    I'm sure i'll have a few questions on that later on today - but i got a good head start on how i'm going to code the simple program (its amazing how fast you forget stuff - just last september - i was taking advanced intro to C++ - and creating a unix text based menu driven database program for keepign track of college football teams and records - few thousand lines of code - saving to files - opening and editing, and now - i can't even remember half of that crap!)
     
  19. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    I'm confused, both are standalone, what's the advantage of going to the executable? This makes no sense.
     

Share This Page