Saved Bookmarks
| 1. |
Solve : Using If to bypass processing in a batch file-not working? |
|
Answer» ENVIRONMENT Windows Server 2000 SP version 5 service pack 4. I need to check if a FILE has data. If not I want to bypass sending the file to print and backing up the contents. I tried code from example in ch000754 but it's not working for me. This is what I've tried. I want to bypass the processing between the IF and :PDFTP. IF DallasPrintFile.ps equ 5 GOTO PDFTP . . . :PDFTP 5KB is the filesize if there is nothing to print in the fileIF doesn't work that way. it compares STRINGS. Nothing else. The only thing that will ever "equal" "DallasPrintFile.ps" is "DallasPrintFile.ps", or a variable that expands to that value. Read ch000754 again. Note the section about FOR. I must say that help section is rather poorly written. It talks about "a file equal to 0" when it is discussing a file whose size is equal to 0 bytes. Maybe that's where your confusion arose? Any suggestion as to how I might accomplish my goal or is it not possible? If the filesize is 5kb I want to bypass all processing of itI just told you. Read ch000754 again. I failed to mention that I tried the For also and it didn't work either. This is what I used for /F %%A in ("DallasPrintFile.ps") do If %%~zA equ 5kb goto PDFTP . . . . . :PDFTPQuote from: tonibooker on September 11, 2007, 11:57:44 AM I failed to mention that I tried the For also and it didn't work either. This is what I used OK I'll go through it step by step. First of all we need to find out the file size of DallasPrintFile.ps. So we use the ~z feature of FOR to get the size. We will put it in a variable called fsize. We will use the /a (arithmetic) switch with the SET command. That way we can do a size comparison. Quote for /F %%A in ("DallasPrintFile.ps") do set /a fsize=%%~zA The file size is given in bytes. e.g. now we could do Quote echo size of file is %fsize% bytes Did you mean the file size is exactly 5 kb? And is that 5 K binary, i.e. 5 x 1024 bytes (5120 bytes)? Or 5,000 bytes? on the properties it list the file as size 4.19KB(4,299 bytes) size on disk 8.00KB(8,192 bytes) Looking at file in windows explorer size is listed as 5KBLet me get this straight. The filesize is exactly 4299 bytes if there is nothing to print? Always? Never more or less? You're quite sure? I want to get this right. Yes it will always be that size if there is nothing to print.Quote from: tonibooker on September 11, 2007, 03:38:35 PM Yes it will always be that size if there is nothing to print. Try this... for /F %%A in ("DallasPrintFile.ps") do set /a fsize=%%~zA if "%fsize%" LEQ "4299" goto noprint REM code to be executed if there is REM something to print goto end :noprint echo nothing to print :end Thanks for you patience, I give it a tryWhen the FOLLOWING line is executed in a batch file. The message "missing operand" is generated. I'm not familiar enough with DOS commands to troubleshoot this. I've searched for the format and all the results look like this is correct but obviously something is not quite right.I've coded it with a LOWERCASE 'a' and the uppercase 'A' after the 'do set...' Could you tell me what the missing operand is? for /F %%A in ("DallasPrintFile.ps") do set /A fsize=%%~zA The following returns nothing before 'bytes' echo size of file is %fsize% bytesDoes the file exist? Is the filename exactly as shown? Is the batch being run in the same folder? Yes the file exist and the name is exactly as written. It is not being executed from the same folder. I tried send a screen shot but it didn't work Quote from: tonibooker on September 13, 2007, 09:59:36 AM It is not being executed from the same folder. That is why it isn't working. If the DallasPrintFile.ps is not in the same folder as the batch file, then you need to add the drive letter and full path like this... Don't copy this, substitute the proper drive letter and path! for /F %%A in ("D:\Folder\Subfolder\Another Folder\DallasPrintFile.ps") do set /A fsize=%%~zA |
|