Solved

Loop through recordset and copy files to another folder

Posted on 2013-05-10
7
336 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dynamic? Dropdown Box 29 71
Visual Project Bridge error 5 70
Error viewing ASP page 12 146
Query not working correctly? (or how i want it to... 6 48
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

919 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

13 Experts available now in Live!

Get 1:1 Help Now