Re: Output file

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Monica,

Basically this line could be translated into the following pseudocode:

For every file in the array represented by the variable filename set the
variable filesize to the size of the file.

Two things to note here:
1. Even though you only entered one filename, the script is treating the
variable as an array of filenames, hence the "for every file do a command"
syntax.
2. %%~zA returns the size of the file.

I hope this explains it better.

Regards,
Jonathan



"Monica" <Monica@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:993DB9A1-19CD-46EB-8828-3867C2CFE0FF@xxxxxxxxxxxxxxxx
Thanks Jonathan,

This worked OK. Though I do not understand what the command for %%A in
(%filename%) do set "filesize=%%~zA" does. Could you explain?

Regards,

Monica

"Jonathan Psaila-Depasquale" wrote:

Hi Monica,

I've taken the course of action you suggested in the last paragraph and
wrote you a small dos script that carries this out for you. Note that
you
should append the osql command to the beginning of this script. The
script
assumes that you send your data to a text file called tempresults.txt.
You
use that name to check for file size. If the file size = 0 bytes you
delete
the file. If the file size > 0 bytes you rename the file to results.txt.
Note that you have to run the script from the directory in which the file
tempresults.txt resides. Otherwise please adapt the script to include
the
necessary directory paths.

--------------------

echo off

if not exist tempresults.txt GOTO EXITTO

set "filename=tempresults.txt"

for %%A in (%filename%) do set "filesize=%%~zA"

if "%filesize%"=="0" GOTO ZEROFILESIZE
rename tempresults.txt results.txt
echo File was greater than 0 bytes
GOTO EXITTO

:ZEROFILESIZE
del tempresults.txt
echo File was 0 bytes

:EXITTO

echo on

--------------------

Any questions please let me know.

Regards,
Jonathan



"Monica" <Monica@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5239413C-2947-43AF-B7BE-4CE0C829E55D@xxxxxxxxxxxxxxxx
I have an osql statement that queries a database.

If the query returns any rows I want them written to a file, so I
redirected
the output of my osql statement to a file (results.txt). But if there
are
no
rows that comply with the condition of the query I do not want any
files
created. The way I have it now an empty file is created.

This is my osql statement:
osql -U sa -S myserver -d db_Where -n -i c:\SQLquery.txt -o
c:\results.txt

Is there a way I can write this so that no output file is created when
no
rows comply with the query condition?

I was thinking of checking the file size and if it is zero then delete
the
file, but I do not know how to do that either from a .bat file. Can it
be
done?






.



Relevant Pages

  • LongestRunningQueries.vbs - Using a VB Script to show long-running queries, complete with qu
    ... Try this script to see what queries are taking over a second. ... you need a long-running query. ... Clicking on SQL opens the full SQL batch as a .txt file, ... filename = temp & filename ...
    (comp.databases.ms-sqlserver)
  • Re: Output file
    ... should append the osql command to the beginning of this script. ... echo File was greater than 0 bytes ... If the query returns any rows I want them written to a file, ...
    (microsoft.public.sqlserver.mseq)
  • Re: Output file
    ... should append the osql command to the beginning of this script. ... echo File was greater than 0 bytes ... If the query returns any rows I want them written to a file, ... the output of my osql statement to a file. ...
    (microsoft.public.sqlserver.mseq)
  • Re: HELP! Need AD Query for Last login
    ... query the DCs in the USA domain, how would I modify the script? ... I'm new to VB script and making this simple modification is beyond me at ... >> ' Because the lastLogon attribute is not replicated, ... Then, for each Domain Controller, ADO is used to search the ...
    (microsoft.public.scripting.vbscript)
  • Re: LDAP query information
    ... a "Dim" statement. ... script is run. ... Microsoft MVP Scripting and ADSI ... Can you please provide me info on what to do with the below query? ...
    (microsoft.public.windows.server.scripting)