Solved

Script to find a filename

Posted on 2010-11-16
6
274 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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
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.

831 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