General discussion


Need VB6 code to renname files using a database

By kennethaj ·
I am hoping someone can write and give me a simple VB6 app that renames files using criteria defined in a csv file. I have found no existing apps that do exactly what I need. What I have are jpg's that need to be renamed. The CSV file contains 2 columns. Column 1 has the existing name of a jpg file, column 2 has the new filename. What I need the app to do is prompt for the diretory that contains the jpg's and csv file, then prompt for the CSV file name that contains the renaming criteria, and then prompt for the directory where the renamed files would be placed(destination dir). I would like the app to read each line of the CSV file, and process the jpg's until the end of the file is reached. So, the script would read the first filename, copy the jpg with that filename into the new directory, then rename it with the filename in column 2 of the CSV. EX: column1 has "picture09092003.jpg", and column2 has "900032CE10BA.main.jpg". The script would copy the file named "picture09092003.jpg" to the destination directory, and then rename it "900032CE10BA.main.jpg". It would process all the records in the CSV unitl all jpg files have been copied and renamed. If anyonw can help, thanks.

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
Thread display: Collapse - | Expand +

All Comments

Collapse -

by johnmaxy In reply to Need VB6 code to renname ...

go to digitalmatrix and download the free program "my album". With this one you can rename files the way you want..

Collapse -

by kennethaj In reply to
Collapse -

by tech_wiz03 In reply to Need VB6 code to renname ...

your question asked for a vb6 program read the cvs file and preform the operation. Here's a stab at it:

' program to copy from source to destination with ' rename
srcpth$=inputbox$(".jpg sources are in...","source file path")
destpath$=inputbox$("send to path...","destination file path")
cvsfile$=inputbox$("transscribe is...","rules file ")
open srcpth$+"\"+destpath$ for input as #1
while not eof(1)
input #1,fil1$,fil2$
shell "copy "+srcpth$+fil1$+" "+destpth$+fil2$
' kill srcpth$+fil1$ ' remove rem statement to 'remove the source


Collapse -

by MadestroITSolutions In reply to Need VB6 code to renname ...

I made the application under your specs. Drop me a line at and I will be more than happy to send it to you by e-mail. The only thing I ask in return is that you rate my answer. I have stopped checking the forums lately because people just take the answer and don't give the points.

Your question is great and well focused on the subject of this forum, programming.
I would also like to take the time on this answer (I hope you don't mind) to send a little message to other users out there:


This forum's category is programming, so please, ASK PROGRAMMING QUESTIONS ONLY.

Will save you and everyone else time.

My 2 cents.


Collapse -

by kennethaj In reply to

I received the files you sent. Thank You. They will be a great help.

Collapse -

by kennethaj In reply to Need VB6 code to renname ...

I have already figured out how to do it. It may not be efficient since I'm not a programmer, but it did the job and saved me a week of work. My code is pasted below.

To Wiz03..I tried your code, but it gave the error message "bad file name or number" when it reached the line "open srcpth$+"\"..." I'll give a chance for the other poster to send their code, and if their code generates an error, I'll give you the points for posting first. If their code does not generate an error, I'll give them the points. Fair?

To KeeBored, I will email you, and will award the 1000 points to whichever code works best between you and Wiz03. Fair?

Here was my try at it:
Private Sub cmdRename_Click()
Dim strSource, strDest, strcsv, strOj, strNj As String
Dim strOpOn, strNpOn As String
strSource = txtSource.Text
strDest = txtDest.Text
strcsv = txtCsv.Text
Open strcsv For Input As #1
Do While Not EOF(1)
Input #1, strOj, strNj
picOld.Print strOj
picNew.Print strNj
strOpOn = strSource + strOj
strNpOn = strDest + strOj
strNpNn = strDest + strNj
Set fs = CreateObject("scripting.filesystemobject")
fs.copyfile strOpOn, strNpOn, overwrite
Name strNpOn As strNpNn
End Sub
Thanks for the ideas though.

To KeeBored, I will email you, and will award the 1000 points to whichever code wors best between you and Wiz03.

Collapse -

by kennethaj In reply to Need VB6 code to renname ...

This question was closed by the author

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums