Thursday, March 7, 2013

Word Verification Added + Bonus

After the silly amounts of spam I've been getting, I've added word verification to comments. Now hopefully I only see the one or two comments I get per month to approve and not the dozens of fake spam messages pretending to sound real.

Might as well make this post a little more useful.

If there's one batch command for command prompt programs you'll want to know, it's this one.

    for %%f in (*.ext) do (
            echo %%~nf
            executable "%%~nf.ext" "%%~nf"

This batch command is useful for tools which take one file and output another, but you can modify it from there to get different results. What it's doing is it filters files in the current folder to the extension you specify. On the third line, you can tell the program what to do. Executable is the name of the program you're using. Then you follow its usage instructions to have it function correctly. You can add options wherever they must go. In this case, there are no options but could go after executable and before "%%". The last variable on the line is the output file. It is currently set up so output files have the same name as the input file, but you can add a different file extension or anything you want. It can say "filename_OUT", so you don't mix up the original files with the converted ones.

Try it out! You can thank me later.


Prof. 9 said...

A snippet I've been using a lot lately:

for /f "delims=" %%i in ('^
#command# ^
') do (
echo %%i
set result=%%i
if not "%result%"=="Message" goto :error
exit /b 0
exit /b 1

Replace #command# with the command of your choosing (don't remove the ^). Command line tools usually set the ERRORLEVEL to >0 when an error occurred, which is easily processed by a batch script (IF ERRORLEVEL 1) but there are some that don't do just and just print out an error. With this snippet, you can check the last line that was printed to the console, which could be the error message you're looking for. If an error occurred, you can then PAUSE, or whatever, and return ERRORLEVEL to the calling script.

Post a Comment