|
-
Oct 16th, 2006, 05:19 PM
#1
Thread Starter
New Member
[RESOLVED] rename files in file listbox
How do I rename files I placed into a file listbox. The new file name will be entered in a text box. I also want the files to be sequential (myFilex, myFilexx, myFilexxx, etc) if the file exists then continue the numbering scheme.
Last edited by myvbopps; Oct 16th, 2006 at 05:21 PM.
Reason: misspelling
-
Oct 16th, 2006, 05:33 PM
#2
Re: rename files in file listbox
Welcome to the forums! 
What do you mean with, place into a file listbox?
Try something like this:
VB Code:
Option Explicit
Dim i As Integer
Private Sub Command1_Click()
Dim sPath As String: sPath = File1.Path
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
For i = 0 To File1.ListCount - 1
Name (sPath & File1.List(i)) As (sPath & Text1.Text & String(i + 1, "x"))
Next i
File1.Refresh
End Sub
Last edited by gavio; Oct 16th, 2006 at 05:50 PM.
-
Oct 17th, 2006, 05:33 AM
#3
Thread Starter
New Member
Re: rename files in file listbox
Sorry , what I ultimately want is to select files in a file list box, place them into a list box and rename and move them into a directory of my coice. I have accomplished everything except renaming and moving.
-
Oct 17th, 2006, 06:37 AM
#4
Re: rename files in file listbox
Welcome to the forums. 
Renaming a file is fairly straightforward.
VB Code:
Name "c:\temp.txt" As "c:\temp2.txt"
Once renamed, you can "move" it using FileCopy
VB Code:
FileCopy "c:\temp2.txt", "c:\differentfolder\temp2.txt"
Kill "c:\temp2.txt"
These can be incorporated to use your listbox entries.
-
Oct 17th, 2006, 07:34 AM
#5
Thread Starter
New Member
Re: rename files in file listbox
I think I've totally confused matters. Here is what I am attempting:
To write a program that will rename selected files from 001 to how many files were selcted. I have list boxes that show the files and directories. I want to be able to select the files from the list box, press the command button and have the selected files renamed according a textbox text. Sorry for confusing matters!!
-
Oct 17th, 2006, 08:44 AM
#6
Re: rename files in file listbox
Ok. Put FileListBox, ListBox, TextBox and CommandButton on your form and try the folowing code (select files you want to rename and click the button):
VB Code:
Option Explicit
Dim i As Integer
Private Sub Command1_Click()
Dim counter As Integer: counter = -1
Dim sPath As String: sPath = File1.Path
List1.Clear
For i = 0 To File1.ListCount - 1
If File1.Selected(i) = True Then
List1.AddItem File1.List(i)
End If
Next i
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
For i = 0 To List1.ListCount - 1
counter = counter + 1
Name sPath & List1.List(i) As sPath & Text1.Text & Format(counter, "00#")
Next i
File1.Refresh
List1.Clear
MsgBox "Done!"
End Sub
-
Oct 17th, 2006, 08:58 AM
#7
Re: rename files in file listbox
You might want to place the counter in the base name rather than appending it to the extension
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|