Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move Files Depending on File Size.... ...Error Occured 2

Status
Not open for further replies.

comnetlimited

Technical User
Oct 7, 2003
68
PG
Hi,
I am newbie to VBScript. Below is a VBScript I wrote in Notepad (is there a proper software to use to write VB Script so that syntax can be checked??) and then save as Clear Error Folders.vbs on my deskstop.

What I am tryin to achieve is to move ONLY files that has a size of 1 KB From My Error folder to Data Folder.

Shown below is my below is my script.
Note i use >= 1 (??? is 1 KB = 1 ) for testing purposes only, just to see if the script can work.

++++++++++++++++++++++++++++++++++++++++++++++++++
Sub ProcessFiles()
dim oFile

Set FSO = CreateObject("Scripting.FileSystemObject")
Set Data = FSO.GetFolder("D:\Data")
Set Error = FSO.GetFolder("D:\Error")

For Each oFile In Error.Files
If oFile.size >= 1 then
FSO.MoveFile "D:\Error\" & (oFile.Name) , Data
End if
Next

End Sub

Call ProcessFiles
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

However, it comes up with an Error:

Script: C:\Documents and Settings\mnarewec.stcheadoffice\Desktop\Clear Error Folders.vbs

Line: 10
Char: 4
Error: File already exists
Code: 800A003A
Source: Microsoft VBScript runtime Error

But Honestly, there is no file(s) in folder D:\Data

Please somebody help.

Thank you in advance
 
My 2 cents:
Code:
Option Explicit
Sub ProcessFiles()
Dim FSO, oError, oFile
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oError = FSO.GetFolder("D:\Error")
For Each oFile In oError.Files
If oFile.Size >= 1024 Then
   FSO.MoveFile oFile.Path, "D:\Data\", True
End If
Next
End Sub

Call ProcessFiles

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you PHV and TSUJI...for your greate Help.

Actually what I was trying to achieve is to delete files that has less than 1KB and also delete files which has file extension of "err" (Error and Move move other files to the folder D:\Data

It worked fine by deleting the 1KB size files, but it seems the code for determining the file Extension is not working. That is it is deleting the 1KB files by Moving ALL files (including the error files ) to D:\Data

Here is my Code
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Option Explicit
Sub ProcessFiles()
Dim FSO, oError, oFile
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oError = FSO.GetFolder("D:\Error")
For Each oFile In oError.Files

If oFile.Size <= 1024 Then
FSO.DeleteFile oFile.Path
Else
If left(oFile.Name,3) = "ERR" Then
FSO.DeleteFile oFile.Path
Else
FSO.MoveFile oFile.Path, "D:\Data\"
End If
End If

Next
End Sub

Call ProcessFiles
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
By the PHV, your code {FSO.MoveFile oFile.Path, "D:\Data\", True} did not work, it comes up with error so I have to remove the TRUE and it works perfectly...thanks

Thanks in advance for your help.
 
Replace this:
If left(oFile.Name,3) = "ERR" Then
By this:
If UCase(Left(oFile.Name, 4)) = ".ERR" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV Thanks,
But I use your example in another post and got it Right.
I replace
If left(oFile.Name,3) = "ERR" Then
with
If Lcase(Right(oFile.Name,3)) = "err" Then

And it works fine. File Extension are three Last Char of the File Name therefore I think Lcase(Right(oFile.Name,3)) works fine.

BTW thanks for the quick response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top