Solved

Loop through recordset and copy files to another folder

Posted on 2013-05-10
7
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 53

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 53

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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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 53

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 53

Expert Comment

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

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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/…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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