1.

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

Answer»

Hello all,

I want to open TXT and LOG files with different programs, depending on the file size.

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 LOT bigger (> 4Mb), so I don't want to use it for any small file.

So I wrote the following batch script:

Code: [Select]REM OPENTXT.BAT
ECHO is %~z1 greater than 20000?
if %~z1 GTR 20000 (ECHO YES) ELSE (ECHO NO)
IF %~z1 GTR 20000 (start "C:\LiberKey\Apps\PSPad\PSPadLKL.exe" %1) else (start "C:\Arquivos de programas\win32pad\win32pad.exe" %1)
exit

And then I run OPENTXT.BAT MYFILE.TXT

The first three lines I put just for me to CHECK if the file size is being got correctly.

Anyway, no matter what the size of the MYFILE.TXT is, it ALWAYS 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.

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.

If I type on the command line WIN32PAD.EXE MYFILE.TXT, it opens fine.

Any ideas?

OK, I seemed to have solved it myself:

Code: [Select]IF %~z1 gtr 3500 (goto 1) else (goto 2)
exit

:1
start "1" "C:\LiberKey\Apps\PSPad\PSPadLKL.exe" %1
GOTO:EOF

:2
start "2" "C:\Arquivos de programas\win32pad\win32pad.exe" %1
GOTO:EOF

I associated TXT files with this batch file, and it's working.

I think it had something to do with me ADDING the "Window TITLE" in the START option.



Discussion

No Comment Found