+ Post New Thread
Results 1 to 7 of 7
Scripts Thread, Batch file help in Coding and Web Development; I've been messing around with batch files for a while, and I can generally get them to do what I ...
  1. #1

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,160
    Thank Post
    599
    Thanked 1,982 Times in 1,368 Posts
    Blog Entries
    19
    Rep Power
    836

    Batch file help

    I've been messing around with batch files for a while, and I can generally get them to do what I want.

    However, one of the files I've been using seems a bit clunky... I feel that there's an easier way to do it.


    Can anyone give any advice/suggestions? [Note advice/suggestions. I don't want answers... yet.]


    Code:
    DIR \\[server]\[path]\Applications /B > TempA.txt
    DIR \\[server]\[path]\Tools /B > TempB.txt
    SET date=%date:/=-%
    IF EXIST "\\[LONG FILE PATH!]\Software list %date%.txt" GOTO END
    TYPE "TempA.txt" | FINDSTR /I /V "KB.* Update Security" >>"\\[LONG FILE PATH!]\Software list %date%.txt"
    TYPE "TempB.txt" | FINDSTR /I /V "KB.* Update Security" >>"\\[LONG FILE PATH!]\Software list %date%.txt"
    :END
    DEL TempA.txt
    DEL TempB.txt

    Also, what's a good way of commenting code? I go back to things months later and have no clue what commands do...

    I know HOW to do it, but I'm not sure if there is a proper way to do it so it doesn't look stupid.

  2. #2
    themightymrp's Avatar
    Join Date
    Dec 2009
    Location
    Leeds, West Yorkshire
    Posts
    1,219
    Thank Post
    216
    Thanked 226 Times in 195 Posts
    Rep Power
    73
    Not sure about how to tidy up / speed up your script but I always comment mine like this:

    REM *******Heading*****************************
    REM ****Comments here ****
    REM ****Comments here ****
    REM ******************************************

  3. Thanks to themightymrp from:

    X-13 (18th May 2012)

  4. #3

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    1,985
    Thank Post
    114
    Thanked 505 Times in 340 Posts
    Blog Entries
    2
    Rep Power
    286
    Rather than piping dir to a file, I tend to use for loops

    e.g.

    Code:
    for /F "usebackq" %%f IN (`dir stuff.txt /b /l`) do call :myroutine %%f
    goto :eof
    further down, I define my routine. It's not a true subroutine, but it's as close as you can get with batch.
    Code:
    :myroutine 
    echo I'm working with file %1
    goto :eof

  5. Thanks to jinnantonnixx from:

    X-13 (18th May 2012)

  6. #4

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    1,985
    Thank Post
    114
    Thanked 505 Times in 340 Posts
    Blog Entries
    2
    Rep Power
    286
    As for comments, I use two colons (::)
    One colon is used for labels, but two can be used for comments.

    Code:
    :: this program is fantastic
    echo Hello

  7. Thanks to jinnantonnixx from:

    X-13 (18th May 2012)

  8. #5

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,160
    Thank Post
    599
    Thanked 1,982 Times in 1,368 Posts
    Blog Entries
    19
    Rep Power
    836
    Quote Originally Posted by jinnantonnixx View Post
    As for comments, I use two colons (:
    One colon is used for labels, but two can be used for comments.

    Code:
    :: this program is fantastic
    echo Hello
    Yeah, I was playing about with "::" as we have a few files from our LEA that are commented like that.

    Code:
    :: This is an awesome reply
    SONG /Lionel /Richie
    echo Is it me you're looking for?

  9. #6

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,600
    Thank Post
    109
    Thanked 769 Times in 598 Posts
    Rep Power
    181
    Not strictly help with making your batch file less clunky but have you considered an alternative script language? PoerShell has extremely powerful string handling (which is basically all you are doing) so it could be a time to learn?

    Also... put your date check at the start of the script... no point running the first two lines if you are then going to skip to the end.

  10. Thanks to Ric_ from:

    X-13 (18th May 2012)

  11. #7

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,160
    Thank Post
    599
    Thanked 1,982 Times in 1,368 Posts
    Blog Entries
    19
    Rep Power
    836
    Quote Originally Posted by Ric_ View Post
    Also... put your date check at the start of the script... no point running the first two lines if you are then going to skip to the end.
    I code how I think... in a random sequence determined by the order of when I actually think of it.

    But that is a good idea...

SHARE:
+ Post New Thread

Similar Threads

  1. quick batch file help
    By MK-2 in forum Coding
    Replies: 1
    Last Post: 5th August 2011, 02:10 PM
  2. batch file help
    By marc2510 in forum Scripts
    Replies: 5
    Last Post: 13th July 2011, 08:21 PM
  3. Batch File (select random file) help
    By fil_b in forum Windows Server 2000/2003
    Replies: 5
    Last Post: 5th November 2009, 04:13 AM
  4. Replies: 12
    Last Post: 11th October 2008, 11:37 PM
  5. batch file help
    By beeswax in forum Scripts
    Replies: 9
    Last Post: 3rd March 2006, 07:48 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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