X-13 Posted May 18, 2012 Posted May 18, 2012 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.] 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.
themightymrp Posted May 18, 2012 Posted May 18, 2012 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 ****************************************** 1
jinnantonnixx Posted May 18, 2012 Posted May 18, 2012 Rather than piping dir to a file, I tend to use for loops e.g. 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. :myroutine echo I'm working with file %1 goto :eof 1
jinnantonnixx Posted May 18, 2012 Posted May 18, 2012 As for comments, I use two colons (: One colon is used for labels, but two can be used for comments. :: this program is fantastic echo Hello 1
X-13 Posted May 18, 2012 Author Posted May 18, 2012 As for comments, I use two colons (: One colon is used for labels, but two can be used for comments. :: 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. :: This is an awesome reply SONG /Lionel /Richie echo Is it me you're looking for?
Ric_ Posted May 18, 2012 Posted May 18, 2012 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. 1
X-13 Posted May 18, 2012 Author Posted May 18, 2012 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...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now