Solved

Renaming Files

Posted on 1999-01-29
5
232 Views
Last Modified: 2010-05-03
How would you open the files in a given directory and rename them one after another without knowing the exact name of each file in the directory, just the file extension?
0
Comment
Question by:timothy1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Accepted Solution

by:
sbmc earned 50 total points
ID: 1471239
a=dir("c:\*.*")
do until a=""
   name "c:\" & a as "c:\old" & a
   a=dir
loop

this will rename all files with a prefix of old
0
 
LVL 1

Expert Comment

by:rayford
ID: 1471240
assume a simple form with three textboxes named textbox1,2,3 and a single command button named command1.
given contents of the textboxes as follows
Text1.text="C:\test"      'path to folder to rename files in
Text2.text="txt"          'filespec extension to rename
Text3.text="bak"          'rename all TXT files to BAK's

click command button code to perform the rename would be:

Private Sub Command1_Click()
Myfile = Dir(Text1 & "\*." & Text2)
While Myfile <> ""
    Name Text1 & "\" & Myfile As Text1 & "\" & Left(Myfile, Len(Myfile) - Len(Text2)) & Text3
    Myfile = Dir
Wend
End Sub

This is assuming the only thing changing was the file extension on the rename.  You would alter the code slightly to get other results.
0
 

Author Comment

by:timothy1
ID: 1471241
I put the following code into a form and a bunch of files on my d: drive. It worked great! except that it just put a prefix on the existing file name ie. old.name.txt

I want to rename variousnames.txt to read newname.txt, not just put a prefix on the old name.

Private Sub cmdRename_Click()
Dim a
a = Dir("D:\*.*")
Do Until a = ""
   Name "D:\" & a As "D:\old" & a
   a = Dir
Loop

'this will rename all files with a prefix of old
MsgBox "Done!"
End Sub

0
 

Expert Comment

by:dudemann
ID: 1471242
You could also check out my shareware utility:  File Name Case Converter.  It can be found at:  http://www.primenet.com/~danield/netutilz/netutilz.htm.  

Dan.
0
 

Author Comment

by:timothy1
ID: 1471243
Well I looked up dir() and name in Online Boxs and then rewrote the above to fit my own needs.

Thanks anyway.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month3 days, 19 hours left to enroll

630 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