1.

Solve : DOS Batch command to open file with certain program, depending on file size?

Answer» <html><body><p>Hello all,<br/><br/>I want to open TXT and LOG files with different programs, depending on the file size.<br/><br/>For instance, if it's just a small file, I'm happy to open it up in WIN32PAD, which is small and opens fast. But if it's a larger file, then I want to open it in PSPad, my preferred text editor. But PSPad is a <a href="https://interviewquestions.tuteehub.com/tag/lot-770427" style="font-weight:bold;" target="_blank" title="Click to know more about LOT">LOT</a> bigger (&gt; 4Mb), so I don't want to use it for any small file.<br/><br/>So I wrote the following batch script:<br/><br/> Code: <a>[Select]</a>REM OPENTXT.BAT<br/>ECHO is %~z1 greater than 20000?<br/>if %~z1 GTR 20000 (ECHO YES) ELSE (ECHO NO)<br/>IF %~z1 GTR 20000 (start "C:\LiberKey\Apps\PSPad\PSPadLKL.exe" %1) else (start "C:\Arquivos de programas\win32pad\win32pad.exe" %1)<br/>exit<br/><br/>And then I run OPENTXT.BAT MYFILE.TXT<br/><br/>The first three lines I put just for me to <a href="https://interviewquestions.tuteehub.com/tag/check-25817" style="font-weight:bold;" target="_blank" title="Click to know more about CHECK">CHECK</a> if the file size is being got correctly.<br/><br/>Anyway, no matter what the size of the MYFILE.TXT is, it <strong><a href="https://interviewquestions.tuteehub.com/tag/always-373607" style="font-weight:bold;" target="_blank" title="Click to know more about ALWAYS">ALWAYS</a></strong> opens it with PSPAD. The first lines echo the result (true or false) for the GTR operator, which confirms that the logical operator is returning the expected result.<br/><br/>I tried changing things round and using LEQ instead of GTR, but it still opens all files with PSPAD, no matter what the result of GTR (or LEQ) is.<br/><br/>If I type on the command line WIN32PAD.EXE MYFILE.TXT, it opens fine.<br/><br/>Any ideas?<br/><br/>OK, I seemed to have solved it myself:<br/><br/> Code: <a>[Select]</a>IF %~z1 gtr 3500 (goto 1) else (goto 2)<br/>exit<br/><br/>:1<br/>start "1" "C:\LiberKey\Apps\PSPad\PSPadLKL.exe" %1<br/>GOTO:EOF<br/><br/>:2<br/>start "2" "C:\Arquivos de programas\win32pad\win32pad.exe" %1<br/>GOTO:EOF<br/><br/>I associated TXT files with this batch file, and it's working.<br/><br/>I think it had something to do with me <a href="https://interviewquestions.tuteehub.com/tag/adding-849193" style="font-weight:bold;" target="_blank" title="Click to know more about ADDING">ADDING</a> the "Window <a href="https://interviewquestions.tuteehub.com/tag/title-246221" style="font-weight:bold;" target="_blank" title="Click to know more about TITLE">TITLE</a>" in the START option.</p></body></html>


Discussion

No Comment Found