Solved

Loop through recordset and copy files to another folder

Posted on 2013-05-10
7
339 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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 …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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