Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming Directories programmatically? 2

Status
Not open for further replies.

WildWest

Programmer
Apr 2, 2002
111
US
I’m looking for an application that will recursively rename files and directories. Does anyone have one?

For example, I want to change the space character “ “ to the underscore “_” in all files names and directories. If you don’t have it, please let me know if you know where I can find one. Thanks a bunch!!! I appreciate your help.
 
Below is the code for all fiels in a particualr directory
u have to add in the begining
Implements System.IO

u can do it for sub-directory as well
Nouman

Private Sub ProcessDirectory(ByVal targetDirectory As String)
Dim fileEntries As String() = Directory.GetFiles(targetDirectory)
' Process the list of files found in the directory
Dim fileName As String
Dim i As Integer
Dim usergroupList As New ArrayList()
lstavailableFiles.Items.Clear()

For Each fileName In fileEntries
''do wahatever u want with the filename
' Say Rename file name
Rename(filename, <NewFileName>)
Next fileName

End Sub 'ProcessDirectory
 
and to do the recursively, you could do something like
----------------------------------------------------
Private Sub ProcessDirectory(ByVal targetDirectory As String)
Dim MyFiles As String() = IO.Directory.GetFiles(targetDirectory)
Dim fileName, DirName As String
For Each fileName In MyFiles
Rename(fileName, fileName.Replace(&quot; &quot;, &quot;_&quot;))
Next fileName
Dim MyDirs As String() = IO.Directory.GetDirectories(targetDirectory)
For Each DirName In MyDirs
ProcessDirectory(DirName)
Next
End Sub
------------------------------------------------------

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top