Solved

Script to find a filename

Posted on 2010-11-16
6
276 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

A short article about a problem I had getting the GPS LocationListener working.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

707 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