VB Problem - TechRepublic
General discussion
November 4, 2002 at 05:41 AM
khall3

VB Problem

by khall3 . Updated 23 years, 8 months ago

This is a question I posted about a month ago and I closed it because I thought everything was working great. However, I didn’t notice one problem.

“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.”

Nikki96 gave me this code that worksfairly well. However, if the file is listed in the text file and not in the directory the program stops. I need an error checking section that will allow the program to continue if the file is not found.

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

This discussion is locked

All Comments