Discussion Locked

VB 6.0 Problem

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Ok here is the problem. I have a directory that contains over 35,000 pictures that correspond to products. Each filename is associated with a particular item number. For example, item 00001 has a picture file by the name of 00001.jpg. This is the same for all 35,000 or so pictures. The company has recently been bought by another company that uses the same products but different item numbers. So what I need is a program that will copy the pictures from the picture directory and move them into a different directory with the new companys item number. Example, company 1 has 00001.jpg for item number 00001, company 2 needs 00001.jpg for item number 12345 so the file must be copied and renamed as 12345.jpg. I realize this might be hard to understand so if you need some more explanation let me know. Thank you!

7 replies

by don christner

Is there any relationship between the old # and what the new # is? Since it's two companies, I doubt there is. If there isn't a relationship or rule, I do not see how this could be automated.

Post some more info. someone might have an idea.
Don

by khall3

well i have a text file that is set up like this

00001.jpg, 12345.jpg
00002.jpg, 12346.jpg
00004.jpg, 98723.jpg

the numbers on the left of the comma are from one company and the numbers on the right are from the other company. so it must pull 00001.jpg and copy, rename, and move it to 12345.jpg in a different directory.

by nikki96

Sure.
Assume you have a text file, as yours is, with NO SPACES between the file names and the commas. Also, file names must be ABSOLUTE paths.

I tested this in VB6 and it worked fine. Replace the file name and path with yours.

Private Sub cmdCopy_Click()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s, a
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("C:\Documents and Settings\me\My Documents\VBapps\imageCopy\list.txt")
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
While Not ts.AtEndOfStream
a = Split(ts.ReadLine, ",")
fs.CopyFile a(0), a(1)
Wend ts.Close
End Sub

by nikki96

Oh, some of these are VBA objects, so make sure the reference is in the project.

This discussion is closed to new replies.