Solved

Script to find a filename

Posted on 2010-11-16
6
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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…

730 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