A Monster for Every Season: Summer 2
You can get A Monster for Every Season: Summer 2 now at Gumroad
Results 1 to 11 of 11
  1. - Top - End - #1
    Ogre in the Playground
     
    RogueGuy

    Join Date
    Dec 2006
    Location
    Canuckistan
    Gender
    Male

    Default Creating batch files

    Hi guys, I'm in a pinch at work (this is pretty far outside of my skills), and I need to create a bat file to basically process my data.

    I have: directory with a large number of items in it. These have to be run through an executable with the following argument:

    executable [filepath1] [filename]

    Executable creates a plaintext output file (with given filename and custom extension) with some information in it, so ideally I'd like to use a few elements from the output to create the file name, to easily distinguish between files. Output file is formatted like { "element1" "element2" "element3" }, so ideally I'd like to use some of the output file to make the file name something like element1_element2_element3.extension.

    Finally, a few elements from every single output file have to be gathered into a "superfile", formatted kinda like that:

    {
    "filename1.extension": { "title": "element1", "type": "element2" }
    "filename2.extension": { "title": "element1", "type": "element2" }
    }

    I could do this in VB, but I have absolutely no idea where to start with batch files (my knowledge is limited to basic command line tasks like cd or mkdir). I'd figure it out myself, but it's on a major time crunch so I simply don't have 2 days or so it would take for me to learn it.

    I'd be extremely glad if someone could either help me write an example code (I can fill in the blanks myself), or teach me the basics of what I need to know to do this. Willing to pay a small amount ($40 or so seems fair?), in $CDN, or if you play League of Legends, RP.
    Last edited by Don Julio Anejo; 2013-11-14 at 07:46 AM.
    Quote Originally Posted by Maquise View Post
    Anytime someone tries to bring real-world physics into a RWBY discussion, Blake kills them in self defense.
    Quote Originally Posted by Pastoulio
    VERILY, TOP LANE SHALL BE GUARDED BY A VALIANT KNIGHT,
    YEA, MIDDLE LANE SHALL BE OCCUPIED BY A WIZARD,
    I SAY UNTO THEE, A TEAM SHALL HAVE ONE WOODSMAN TO PATROL THE FOREST,
    FINALLY, AN ARCHER OF PENULTIMATE SKILL SHALL GO TO THE BOTTOM LANE, ACCOMPANIED ONLY BY HIS SQUIRE

  2. - Top - End - #2
    Barbarian in the Playground
     
    Tylorious's Avatar

    Join Date
    Nov 2012
    Location
    Georgia
    Gender
    Male

    Default Re: Creating batch files

    are all of the files you are going to be working with formatted identically?


    Playing Pokemon Y:
    Safari: Charmeleon, Magmar, and Braixen
    DS Friend Code: 3668-7804-7430

    Avatar and Signature by Ceika!

  3. - Top - End - #3
    Ogre in the Playground
     
    RogueGuy

    Join Date
    Dec 2006
    Location
    Canuckistan
    Gender
    Male

    Default Re: Creating batch files

    Quote Originally Posted by Tylorious View Post
    are all of the files you are going to be working with formatted identically?
    Yes, they will be. Only the values of things like element1 and file paths change.
    Last edited by Don Julio Anejo; 2013-11-14 at 08:03 AM.
    Quote Originally Posted by Maquise View Post
    Anytime someone tries to bring real-world physics into a RWBY discussion, Blake kills them in self defense.
    Quote Originally Posted by Pastoulio
    VERILY, TOP LANE SHALL BE GUARDED BY A VALIANT KNIGHT,
    YEA, MIDDLE LANE SHALL BE OCCUPIED BY A WIZARD,
    I SAY UNTO THEE, A TEAM SHALL HAVE ONE WOODSMAN TO PATROL THE FOREST,
    FINALLY, AN ARCHER OF PENULTIMATE SKILL SHALL GO TO THE BOTTOM LANE, ACCOMPANIED ONLY BY HIS SQUIRE

  4. - Top - End - #4
    Ogre in the Playground
     
    Krazzman's Avatar

    Join Date
    Jul 2011
    Location
    Aachen, Germany
    Gender
    Male

    Default Re: Creating batch files

    OK, I never really wrote a .bat myself but here we use external .txt as inputfiles for what that thing has to do.

    Example .bat:
    Spoiler
    Show
    c:\windows\system32\ftp -s:"[PATH TO INPUT DATASET]"
    pause


    then in the .txt file we use as input:
    Spoiler
    Show
    open HOST-ID
    ID
    PW
    cd ..
    lcd d:\

    quote site xlate=ftpansi

    get 'HOST-DATASET' "OUTPUT PATH"

    close
    quit
    bye


    Basically you need to search for a function you can use and then implement it that way. Is there maybe a commandline expert you can shoot an email to? He might know where a good documentation is...
    Have a nice Day,
    Krazzman

  5. - Top - End - #5
    Ogre in the Playground
     
    RogueGuy

    Join Date
    Dec 2006
    Location
    Canuckistan
    Gender
    Male

    Default Re: Creating batch files

    I've figured out some basics, such as how to save a list of data files to a separate list:

    setlocal
    dir /b /s *.exe > list.txt

    But I have no idea how to implement a

    For each item in list.txt do...

    Unfortunately, it's 6AM here so anyone I can contact is probably asleep (and even if they're not, it's still pretty rude). If someone can point me to a good reference, I'd be really grateful too.

    All the ones I've found so far are either extremely basic ("this is a bat file... it runs things.. this is a "Hello World" echo"), or assume extensive previous knowledge of DOS and command line.
    Quote Originally Posted by Maquise View Post
    Anytime someone tries to bring real-world physics into a RWBY discussion, Blake kills them in self defense.
    Quote Originally Posted by Pastoulio
    VERILY, TOP LANE SHALL BE GUARDED BY A VALIANT KNIGHT,
    YEA, MIDDLE LANE SHALL BE OCCUPIED BY A WIZARD,
    I SAY UNTO THEE, A TEAM SHALL HAVE ONE WOODSMAN TO PATROL THE FOREST,
    FINALLY, AN ARCHER OF PENULTIMATE SKILL SHALL GO TO THE BOTTOM LANE, ACCOMPANIED ONLY BY HIS SQUIRE

  6. - Top - End - #6
    Ogre in the Playground
     
    Krazzman's Avatar

    Join Date
    Jul 2011
    Location
    Aachen, Germany
    Gender
    Male

    Default Re: Creating batch files

    Quote Originally Posted by Don Julio Anejo View Post
    Unfortunately, it's 6AM here so anyone I can contact is probably asleep (and even if they're not, it's still pretty rude). If someone can point me to a good reference, I'd be really grateful too.
    Spoiler
    Show


    I don't know if this can help you. Else maybe search for something that resembles what you want in the term of command and google how to use it. The good part about this is that it is old enough that you get enough examples... the bad thing is some specific things are that old that no one is interested in sharing it...
    Have a nice Day,
    Krazzman

  7. - Top - End - #7
    Ogre in the Playground
     
    Krazzman's Avatar

    Join Date
    Jul 2011
    Location
    Aachen, Germany
    Gender
    Male

    Default Re: Creating batch files

    Also are you dead set on using .bat?
    Why don't you make a dirty solution using VB? Then fix it when you have time?
    SAS could probably do what you want too but I am unsure what you are even doing...
    Have a nice Day,
    Krazzman

  8. - Top - End - #8
    Barbarian in the Playground
     
    Lorn's Avatar

    Join Date
    Oct 2007

    Default Re: Creating batch files

    Ok. I'm simulating what I think you have. Correct me if I'm wrong.

    Basically: One directory, several subdirectories, each with a few things that need running through this one program.

    So, something like:

    Spoiler
    Show

    Code:
    BASE FOLDER
    |   1
    |   2
    |   3
    |   4
    |   
    +---SUBDIR 1
    |       1
    |       2
    |       3
    |       4
    |       
    \---SUBDIR 2
            1
            2
            3
            4

    Wherein, SUBDIR [x] is a subdirectory, and the numbers are the files that need running through this executable?

    Without knowing what the individual files are or how the executable file works I can't immediately give you a huge amount of help, though I can probably say how to create the output file - at the end of the argument, add >>output.txt, and it'll append each result to output.txt as a new line in the file. Make sure that that's >> as opposed to >, else it'll just overwrite it each time.

    Beyond that, my guess would be that you're looking to get a way to pick up the filenames as a user input kind of thing, though I'm not immediately sure how to do that automatically - I've not done much .bat stuff for a long, long time. Looking through the stuff I wrote about five years ago there's not much that can help you.

    You might be able to do something with Excel and the concatenate function? Get every single filename into Excel, concatenate them together with the arguments, copy every cell, then paste the raw data into a txt file... though I'm not sure how well that'd work, and it would be *incredibly* clunky. A wildcard (CMD uses * by default) might yield results as well.

  9. - Top - End - #9
    Troll in the Playground
    Join Date
    Jan 2012

    Default Re: Creating batch files

    I've been working on this for a little while now. I need to be going, but here's what I've got so far. Hopefully it will be of some help

    For the initial data processing, you could use something like:

    Code:
    executable C:\file\path *.extension
    That is unless the files do not share the same extension or if they're stored in different directories.


    For the last part, there aren't too many write commands available. The best I can think of involves creating two batch files, "run.bat" and "actual.bat".

    run.bat would look something like this:
    Code:
    executable C:\file\path *.extension
    actual.bat > C:\output.txt
    pause
    And actual.bat would look something like:
    Code:
    @echo off
    echo {
    echo "filename1.extension": { "title": "element1", "type": "element2" }
    echo "filename2.extension": { "title": "element1", "type": "element2" }
    echo }
    You would need to replace the names with variables (declared with the command "set" and called with two %'s).

    So it would look more like:
    Spoiler
    Show
    Code:
    @echo off
    setlocal
    
    set filename1=test
    set title=test
    set element1=test
    set type=test
    set element2=test
    set loop_counter=0
    set total_files=6 ::maybe dir can help here?
    
    echo {
    :whileloop
    echo %filename1%.extension: { %title%: %element1%, %type%: %element2% }
    set /A loop_counter=%loop_counter%+1
    if loop_counter=total_files goto endloop
    goto whileloop
    :endloop
    echo }
    
    endlocal


    I'm not sure about reading the strings that title, element1, type, and element2 represent out of the files.

  10. - Top - End - #10
    Colossus in the Playground
     
    BlackDragon

    Join Date
    Feb 2007
    Location
    Manchester, UK
    Gender
    Male

    Default Re: Creating batch files

    I'm not convinced batch files are the right approach to this, especially when you're not familiar with them--the batch file language in DOS/Windows isn't really all that powerful, y'see. I have no idea how you'd do stuff like reading the contents of the output file and renaming it to match, for instance.

    However, you say you can do this in VB--in all modern versions of Windows there's a thing called the Windows Scripting Host which basically allows you to run VB or Java scripts from a command prompt. In order to use this, you'd write your VBScript (bearing in mind that the scripting host implements its own classes and methods for things like file read/write, so you'll need to look those up), and then call it from a batch file using a command like this:

    CSCRIPT //B //NOLOGO MYFILE.VBS

    WSH is a lot more powerful than the standard batch file parser, so I'd use it for something like this.

  11. - Top - End - #11
    Ogre in the Playground
     
    RogueGuy

    Join Date
    Dec 2006
    Location
    Canuckistan
    Gender
    Male

    Default Re: Creating batch files

    I'm basically told it has to be a bat file, or they won't accept my work.

    Thanks for the help guys, I'm going to play around for a few hours and see what I can do.
    Quote Originally Posted by Maquise View Post
    Anytime someone tries to bring real-world physics into a RWBY discussion, Blake kills them in self defense.
    Quote Originally Posted by Pastoulio
    VERILY, TOP LANE SHALL BE GUARDED BY A VALIANT KNIGHT,
    YEA, MIDDLE LANE SHALL BE OCCUPIED BY A WIZARD,
    I SAY UNTO THEE, A TEAM SHALL HAVE ONE WOODSMAN TO PATROL THE FOREST,
    FINALLY, AN ARCHER OF PENULTIMATE SKILL SHALL GO TO THE BOTTOM LANE, ACCOMPANIED ONLY BY HIS SQUIRE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •