Solved

Script to find a filename

Posted on 2010-11-16
6
270 Views
Last Modified: 2012-05-10
Hey all,

I have a file with a .ERR extension.  I need to monitor that .ERR extension anytime it becomes over 0KB in length.  So I need a script that I can setup as a scheduled task to check that file size. The filename is going to be changed daily, but it will always have and always be the only file with a .ERR extension.  SO the script needs to either find the filename then do a check on the size, or the script can parse through all the files in a folder for anything with a .ERR extension and then check the size.  I do not care if it is a batch or a vbs script. Any ideas?

0
Comment
Question by:digitalhitman00
6 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 300 total points
ID: 34145271
Dim fso
Dim SourceFolder
Dim FileItem

Set fso = CreateObject("Scripting.FileSystemObject")
SourceFolder = "C:\" ''<< your directory

Set SourceFolder = fso.GetFolder(SourceFolder)

For Each FileItem In SourceFolder.Files

    If Right(FileItem.Name, 4) = ".ERR" Then
 
        If FileItem.Size > 0 Then
            ''do something
        End If
       
    End If

Next

Set fso = Nothing
Set FileItem = Nothing
0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 200 total points
ID: 34145467
Parses root and all subdirectories for files with the extension ERR
Outputs filename\size for sizes not equal 0

@echo off

setlocal

set Root=E:\EE\Parse directory

for /r "%Root%" %%a in (*.err) do (

  if NOT "%%~za"=="0" echo %%a\%%~za

)

Open in new window

0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 34145582
I don't know if it will matter in your environment, but with Erick37's approach, you may want to eliminate case from your extension comparisons (Thommy's approach does not suffer this):
sourceFolder = "C:\tmp"
outputFile = "C:\output.txt"

Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.OpenTextFile(outputFile, 8, True, -2)

If fso.FolderExists(sourceFolder) Then
	Set folder = fso.GetFolder(sourceFolder)
	
	For Each file in folder.Files
		If Right(LCase(file.Name), 4) = ".err" And file.Size > 0 Then
			outFile.WriteLine(Date & " " & Time & " - '" & file.Name & "' size is " & file.Size & " bytes")
		End If
	Next
Else
	outFile.WriteLine(Date & " " & Time & " - Target folder does not exist!")
End If

outFile.Close

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 34145600
I forgot to add:  No points for the above  :)
0
 
LVL 19

Expert Comment

by:Thommy
ID: 34145972
@kaufmed:
Thank you for you hint...
;o)))
0
 

Author Closing Comment

by:digitalhitman00
ID: 34154287
both Solutions worked.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now