Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 FSO to iterate through files?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Podge
Support Moderator

Ireland
3775 Posts

Posted - 13 January 2005 :  19:07:37  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message

I have a source folder containing hundreds of gif's
I have a destination folder containing a few gif's (which I don't want to overwrite)

I'm using the File System Object to copy the gif's to the destination using this code

sub copyImages
on error resume next
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	' Check if destination images folder exists. If it doesn't then create it.
	If objfso.FolderExists(pathDest) = False Then
		objFso.CreateFolder (pathDest)
	End if
	objFSO.CopyFile  "c:\wwwroot\articles\*.gif", pathDest, false 'don't overwrite
	set objFso=nothing
on error goto 0
end sub


The code above fails if there is a gif with the same name in both source and destination folders.
If the first gif to be copied raised the error, no gifs would be copied.

I know that I need to create a collection of files (gif's) and iterate through them copying one at a time but I cannot find any code examples anywhere.

Thanx in advance.

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.

Doug G
Support Moderator

USA
6493 Posts

Posted - 13 January 2005 :  19:35:05  Show Profile
You could add some error trapping using on error resume next, then after the copy use if err<> 0 then to decipher what the problem was.

Or, you could spend the computer resources and test for the destination file existence and only copy if the file isn't already there.

======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

Podge
Support Moderator

Ireland
3775 Posts

Posted - 13 January 2005 :  19:49:51  Show Profile  Send Podge an ICQ Message  Send Podge a Yahoo! Message
Thanks for the quick reply Doug.

I already know the error. FSO just stops if it finds a file that's there already and won't continue.

If I had code something like


sub copyImages
on error resume next
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	' Check if destination images folder exists. If it doesn't then create it.
	If objfso.FolderExists(pathDest) = False Then
		objFso.CreateFolder (pathDest)
	End if
        for each i in "c:\wwwroot\articles\*.gif"
	objFSO.CopyFile  i, pathDest, false 'don't overwrite
        next
	set objFso=nothing
on error goto 0
end sub


everytime an error occurred it would move to the next one.

Podge.

The Hunger Site - Click to donate free food | My Blog | Snitz 3.4.05 AutoInstall (Beta!)

My Mods: CAPTCHA Mod | GateKeeper Mod
Tutorial: Enable subscriptions on your board

Warning: The post above or below may contain nuts.
Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 14 January 2005 :  11:43:10  Show Profile
You'll probably need to use the fileexists method there before copying a file over to the new folder.


Search is your friend
“I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.35 seconds. Powered By: Snitz Forums 2000 Version 3.4.07