Solved

Loop through recordset and copy files to another folder

Posted on 2013-05-10
7
333 Views
Last Modified: 2013-05-14
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
Comment
Question by:lshane
  • 4
  • 3
7 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39157637
<%
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
 

Author Comment

by:lshane
ID: 39159018
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
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39159091
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:lshane
ID: 39160318
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
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39160339
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
 

Author Closing Comment

by:lshane
ID: 39165697
Thank you, padas!
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39165727
Awesome!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now