Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBScript to capture files < 1KB

Posted on 2009-04-07
2
Medium Priority
?
353 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
[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
2 Comments
 
LVL 2

Accepted Solution

by:
AlvinLim84 earned 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

636 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