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 ...
-
18th May 2012, 11:29 AM #1 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.
-
-
IDG Tech News
-
18th May 2012, 11:41 AM #2 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 ******************************************
-
Thanks to themightymrp from:
-
18th May 2012, 11:42 AM #3 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
-
Thanks to jinnantonnixx from:
-
18th May 2012, 11:46 AM #4 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
-
Thanks to jinnantonnixx from:
-
18th May 2012, 11:50 AM #5 
Originally Posted by
jinnantonnixx
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?
-
-
18th May 2012, 11:54 AM #6 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.
-
-
18th May 2012, 12:29 PM #7 
Originally Posted by
Ric_
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: 
Similar Threads
-
Replies: 1
Last Post: 5th August 2011, 02:10 PM
-
By marc2510 in forum Scripts
Replies: 5
Last Post: 13th July 2011, 08:21 PM
-
By fil_b in forum Windows Server 2000/2003
Replies: 5
Last Post: 5th November 2009, 04:13 AM
-
By Andie in forum Windows
Replies: 12
Last Post: 11th October 2008, 11:37 PM
-
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
-
Forum Rules