Solved

Renaming Files

Posted on 1999-01-29
5
231 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using Access 8 95
Problem to With line 4 87
RUNRMTCMD from AS/400 13 130
Assign a value in Excel V-Basic 3 38
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

752 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