Solved

VBScript to capture files < 1KB

Posted on 2009-04-07
2
346 Views
Last Modified: 2012-05-06
Hi,

I have a vbscript that will scan a directory and copy files that are less than 1 kb, depending on certain criteria.  It copies those files fine but it also copies the files that are larger than 1kb.
I copied the code below.  
Any help would be appreciated.

Thank you.
strTargetFolder = "c:\test1"

strTargetFolder2 = "c:\test2"

strSourceFolder = "c:\test"

arrDataToFind = Array("test1","test2","test3")

arrDataToFind2 = Array("test4","test5","test6")

Dim FSO, oFolder, oFile

Set FSO = CreateObject("Scripting.FileSystemObject")

Const intForReading = 1

Set ofolder = FSO.GetFolder(strSourceFolder)

For Each oFile In oFolder.Files 

	Set objFile = FSO.OpenTextFile(oFile.Path, intForReading, False)

	strData = objFile.ReadAll

	objFile.Close

	Set objFile = Nothing

	If oFile.Size < 1024 Then

		' Check for the existence of any element from arrDataToFind

		boolMatch1 = False

		For Each strBit In arrDataToFind

			If Instr(LCase(strData), LCase(strBit)) > 0 Then

				boolMatch1 = True

				Exit For

			End If

		Next

		If boolMatch1 = True Then

			'Move file

			FSO.MoveFile oFile.Path, strTargetFolder

		End If

		' Check for the existence of any element from arrDataToFind2

		If boolMatch1 = False Then

			boolMatch2 = False

			For Each strBit In arrDataToFind2

				If Instr(LCase(strData), LCase(strBit)) > 0 Then

					boolMatch2 = True

					Exit For

				End If

			Next

			If boolMatch2 = True Then

				'Move file

				FSO.MoveFile oFile.Path, strTargetFolder2

			End If

		End If

		' Now check if nothing was found, delete the file

		If boolMatch1 = False And boolMatch2 = False Then

			FSO.Deletefile oFile.Path, True

		End If

	End If

Next

Set FSO = Nothing

Open in new window

0
Comment
Question by:cbones
2 Comments
 
LVL 2

Accepted Solution

by:
AlvinLim84 earned 500 total points
ID: 24087832
I think you need to add \ for folder listing at end of the path line. See below. Hope this will help to solve your problem.
strTargetFolder = "c:\test1\"

strTargetFolder2 = "c:\test2\"

strSourceFolder = "c:\test\"

arrDataToFind = Array("test1","test2","test3")

arrDataToFind2 = Array("test4","test5","test6")

Dim FSO, oFolder, oFile

Set FSO = CreateObject("Scripting.FileSystemObject")

Const intForReading = 1

Set ofolder = FSO.GetFolder(strSourceFolder)

For Each oFile In oFolder.Files 

	Set objFile = FSO.OpenTextFile(oFile.Path, intForReading, False)

	strData = objFile.ReadAll

	objFile.Close

	Set objFile = Nothing

	If oFile.Size < 1024 Then

		' Check for the existence of any element from arrDataToFind

		boolMatch1 = False

		For Each strBit In arrDataToFind

			If Instr(LCase(strData), LCase(strBit)) > 0 Then

				boolMatch1 = True

				Exit For

			End If

		Next

		If boolMatch1 = True Then

			'Move file

			FSO.MoveFile oFile.Path, strTargetFolder

		End If

		' Check for the existence of any element from arrDataToFind2

		If boolMatch1 = False Then

			boolMatch2 = False

			For Each strBit In arrDataToFind2

				If Instr(LCase(strData), LCase(strBit)) > 0 Then

					boolMatch2 = True

					Exit For

				End If

			Next

			If boolMatch2 = True Then

				'Move file

				FSO.MoveFile oFile.Path, strTargetFolder2

			End If

		End If

		' Now check if nothing was found, delete the file

		If boolMatch1 = False And boolMatch2 = False Then

			FSO.Deletefile oFile.Path, True

		End If

	End If

Next

Set FSO = Nothing

Open in new window

0
 

Author Comment

by:cbones
ID: 24088067
AlvinLim84,

I do have the \ after the folder name.  When I copied the code over I must have erased it by accident.  
Sorry about that.

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

Title # Comments Views Activity
Automating a script for user accounts LINUX 14 70
VB6 - Convert HH:MM into Decimal 8 52
Is it possible to create a playfile with setacl or icacle? 3 30
MsgBox 4 48
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

896 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

16 Experts available now in Live!

Get 1:1 Help Now