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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recursive file (jpg) search, move then ftp, and finally delete 1

Status
Not open for further replies.

KirbyTank

Technical User
Jul 8, 2010
6
US
Hi Guys,

I've searched the forums and there are many recursive scripts, but I was wondering if anyone can help me out with one a bit more specific.

It's for WindowsXP (mainly) but if works for newer versions is great too!

I want to be able to search all .jpg/.jpeg files in C:\ (and all sub folders)
Then, move all these files into a new folder,
C:\Documents and Settings\User\backuppics (create folder/s if not exist)
(Keep in mind some pics might have the same name, so may need to overwrite or change name)

Then, .zip the backuppics folder. After now having backuppics.zip, delete backuppics folder.

Now, taking backuppics.zip and send to a private server to store for backup.

ftp.backupserver.com
backupuser/backuppass

Then when the upload is finished, delete local backuppics.zip

Can this be done? Trying to do this on my three laptops in the house, it'd be great if the program can run totally in the background to avoid disruption. Maybe a message at the end that says "Backup completed".


I might use this for other file backups, but using jpg as an example.
Any help is most appreciated, thanks!
 
start off with the recursive example in the FAQ and modify the .Files enumeration to check for LCase(Right(aFile.Name, 3)) = ".jpg
 
Hi mrmovie, thanks for pointing in the starting direction.

I have done and changed the code in my file accordingly.
However I get FSO Object Required Error

I searched online for a solution and most users suggested I have a wrong file path, but I do actually have F:\ drive with folder itftestzone

Is there anything else causing the error?
and where can I find the second or third part of the script?
I know this is complicated, and I'm just learning vbs.

Thanks!

=====================
Dim strDir, objDir
strDir = "F:\itftestzone"
Set objDir = fso.GetFolder(strDir)
getInfo(objDir)

Sub getInfo(ByVal pCurrentDir)

For Each aItem In pCurrentDir.Files
'wscript.Echo aItem.Name
If LCase(Right(CStr(aItem.Name), 3)) = ".jpg" Then
'do file manip, copy delete here
End If
Next

For Each aItem In pCurrentDir.SubFolders
'wscript.Echo aItem.Name & " passing recursively"
getInfo(aItem)
Next

End Sub

====================

1. Find files recursively
2. Copy all files to new folder
3. zip folder
4. delete folder
5. FTP upload .zip file
6. delete .zip file
 
Set objDir = fso.GetFolder(strDir)
What is fso ????

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
FileSystemObject" a search on google spitted that out. :)

Anyone else can help me with this?
 
I think the point PHV was making is that your script doesn't yet know what the fso is. According to the code you posted, it has not been declared.

Try adding this to the beginning of your code:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
 
Thanks jges, that fixed the error!!

Right now I'll minimize the complexity of the script.

1. Find all jpgs in C:\ except C:\Program Files, and C:\Windows.
2. Move all found jpgs to new directory

Decided to do manual archiving and backup.
I edited the code but #2 doesn't work. The files are not moved when I try in my testzone.

Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim strDir, objDir, objFileMove, strDestination
strDir = "F:\itftestzone\zone1\"
strDestination = "F:\itftestzone\zone2\"
Set objDir = FSO.GetFolder(strDir)
getInfo(objDir)

    Sub getInfo(ByVal pCurrentDir)

        For Each aItem In pCurrentDir.Files
            wscript.Echo strDir&aItem.Name
           If LCase(Right(CStr(aItem.Name), 3)) = ".jpg" Then
             'wscript.Echo aItem.Name
			 'do file manip, copy delete here
			 ' Delete file if it alread exists in the destination.
				Set objFileMove = FSO.GetFile(strDestination&aItem.Name)
				objFileMove.Delete ()
				Set objFileMove = FSO.GetFile(strDir&aItem.Name)
				 'Move the file destination
	
				objFileMove.Move (strDestination&aItem.Name)
				WSCript.Echo "Moved to " & strDestination&aItem.Name
			End If

        Next

        For Each aItem In pCurrentDir.SubFolders
            'wscript.Echo aItem.Name & " passing recursively"
            getInfo(aItem)
        Next

    End Sub

Also, is it possible to have this script run continuously in the backgrounf or run once on every startup?
Thanks for any help!
 
If LCase(Right(CStr(aItem.Name), [!]4[/!])) = ".jpg" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I want to thank all of you guys for the help!
I kind of got a working script. Not exactly what I wanted at the beginning, but it will definitely help in my backup purposes.

This is literally the *first* time I've touched VBS.

Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim strDir, objDir, objFileMove, strDestination
strDir = "F:\itftestzone\"
strDestination = "F:\itftestzone\zone2\"
Set objDir = FSO.GetFolder(strDir)
getInfo(objDir)

    Sub getInfo(ByVal pCurrentDir)



        For Each aItem In pCurrentDir.Files
                'wscript.Echo pCurrentDir&"\"&aItem.Name
                'jpg/txt/exe.. any file ext
	If LCase(Right(CStr(aItem.Name), 3)) = "jpg" Then
		'wscript.Echo aItem.Name
		'do file manip, copy delete here
		FSO.CopyFile pCurrentDir&"\"&aItem.Name, strDestination&aItem.Name
		'FSO.DeleteFile pCurrentDir&"\"&aItem.Name

	End If

        Next

        For Each aItem In pCurrentDir.SubFolders
            'wscript.Echo aItem.Name & " passing recursively"
            getInfo(aItem)
        Next

    End Sub
Here's the code. It works as far as I see, but if any spots a problem please help point it out.


--
I'd also like if this program can run continuously in the background. How can I do that? Is that recommended?

If not possible, I do not mind running this program at every computer startup. How/Where can I read/learn to do this?

Thanks for any information!
 
>If LCase(Right(CStr(aItem.Name), 3)) = ".jpg"

Or, since you've got the fso ...

If FSO.GetExtensionName(aItem.Name) = "jpg
 
strongm said:
>If LCase(Right(CStr(aItem.Name), 3)) = ".jpg"

Or, since you've got the fso ...

If FSO.GetExtensionName(aItem.Name) = "jpg"

Thanks for the tip, strongm!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top