Solved

Script to find a filename

Posted on 2010-11-16
6
271 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 75

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 75

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

895 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