[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

Script to find the file size and perform an action

When I run the below command it check in the event viewer if there is an event 8001 and dumps the text to a txt file.

eldump  -l application -A 24 -m NTbackup -e 8001  >c:\test.txt

What I want to do is,if this command is successfull then the file size would be more then 1kb other wise file size would be zero.Depending on this criteria I want to run a another commmand.

Can you help me in how I can write a batch file to do this.
1 Solution
Contents of batch file:

@echo off
for %%a in (c:\test.txt) do if %%~za GTR 0 echo %%a is %%~za bytes

If the specified file "c:\test.txt" does not exist or is 0 bytes then the batch file will do nothing and return
If the specified file "c:\test.txt" has a file size greater than 0 (can be modified by changing "GTR 0" to a higher number) then it will echo the filename and file size.
The "echo" command can be replaced with what you really want to do if the test is true.

Let me know if you have any questions.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now