Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

Loop through recordset and copy files to another folder

ASP VBScript
MS Access

Hello.

I have a table with 4,000+ records.
Each record has a field with a path to a single image.

For various reasons, the folder in which the images are located has many more images that I don't need.

So... I would like to loop through the table and for each record I would like to "copy" the image from the path (and its related "xxx_small.jpg" file) into another folder.

After they are all copied, I can delete the original folder and know that the only images I need are in the 2nd folder.



How can I do this using ASP VBScript?


Thank you,
Shane
0
lshane
Asked:
lshane
  • 4
  • 3
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
<%
dim fs
set fs=Server.CreateObject("Scripting.FileSystemObject")

old_folder="c:\httpdocs\mysite\old_images\"
new_folder="c:\httpdocs\mysite\new_images\"

do until rs.eof
     fs.CopyFile  old_folder&rs("image"),new_folder&rs("image")
rs.movenext
loop

set fs=nothing
%>

Open in new window

0
 
lshaneAuthor Commented:
Hi, padas.

Thank you for the reply.

This looks like it will work great, but I can't try it until tomorrow-ish.


So, how would I also include the related small file with a suffix of "_small"?
(I put that in the original question, but I probably didn't articulate it correctly).
0
 
Scott Fell, EE MVEDeveloperCommented:
I just assumed xxx_small.jpg was part of the image name.   If the xxx is what is in the field and not the full name you would do rs("image")&"_small.jpg"
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
lshaneAuthor Commented:
Hi, padas.

No, each image has a related "_small" image.
(i.e.  
path/to/image/Filename1.jpg / Filename1_small.jpg
path/to/image/Filename2.jpg / Filename2_small.jpg
etc.
)

But - only the primary image is in the path in the database.
As it loops through each one, I need it to also pull the related "_small" image.

Is that what your script will do?

I won't be able to test until tomorrow (Because it's at my office), but I want to make sure I have all the script stuff set so I can adapt it when I get there.

Thanks.
0
 
Scott Fell, EE MVEDeveloperCommented:
I guess you would do this

do until rs.eof
     fs.CopyFile  old_folder&rs("image"),new_folder&rs("image")
     fs.CopyFile  old_folder&rs("SmallImage"),new_folder&rs("SmallImage")
rs.movenext
0
 
lshaneAuthor Commented:
Thank you, padas!
0
 
Scott Fell, EE MVEDeveloperCommented:
Awesome!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now