• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 647
  • Last Modified:

Replace charachters in folder names

I have several folders and sub folders which contain pictures. Whenever a folder's name contain the charachter #, the pictures in that folder wiill not be displayed. How can i replace the # sign with the 2 letters No?
0
DrWeb02
Asked:
DrWeb02
  • 4
  • 2
  • 2
  • +1
1 Solution
 
RichardJhancockCommented:
Hi DrWeb02,

You could try a free utility like this one, it allows you to batch rename files and folders:

http://www.bulkrenameutility.co.uk/Download.php
0
 
zkeownCommented:
Can you show the code you're using to look through the folders/files?  It's a pretty easy fix.

replace(folderName, "#", "No")
0
 
RamanaChoudaryCommented:
Dim strDirs() As String = Nothing
 strDirs = Directory.GetDirectories(foldername)

       For Each myfolder As String In strDirs
            Dim myreplace As String = myfolder.Replace("#", "your 2 letters")
        Next
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DrWeb02Author Commented:
This is the code that I had
Protected Sub btnCheckFolderNames_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCheckFolderNames.Click
        CheckMainFolder()
    End Sub
 
    Shared Sub CheckMainFolder()
        ' path to directory 
        Dim myPath As String = "~/SurveyPictures2/"
 
        ' create an instance of the DirectoryInfo object 
        Dim myDirectory As New DirectoryInfo(myPath)
        Replace(myDirectory.ToString, "#", "No")
        CheckSubFolders(myDirectory)
    End Sub
 
    Shared Sub CheckSubFolders(ByVal myDirectory As DirectoryInfo)
        'examine each subfolder in myfolder and replace all "#" with "No"
        For Each folder As DirectoryInfo In myDirectory.GetDirectories
            Replace(folder.ToString, "#", "No")
        Next
    End Sub

Open in new window

0
 
DrWeb02Author Commented:
Thanks for your help. This code changes the name in the array but does not actualy change the name of the folder. So, how do we change the folder name?
Dim mainFolder As String = Server.MapPath("~/SurveyPictures2/")
Dim strDirs() As String = Nothing
strDirs = Directory.GetDirectories(mainFolder)
For Each myfolder As String In strDirs
     Dim myreplace As String = myfolder.Replace("#", "No")
Next

Open in new window

0
 
zkeownCommented:
Change

Replace(myDirectory.ToString, "#", "No")

To

myDirectory = Replace(myDirectory.ToString, "#", "No")
0
 
DrWeb02Author Commented:
Thanks. I appreciate your help. I got to work now and here is the final code:
Dim mainFolder As String = Server.MapPath("~/SurveyPictures2/")

        Dim strDirs() As String = Nothing
        'strDirs = Directory.GetDirectories("~/SurveyPictures2/")
        strDirs = Directory.GetDirectories(mainFolder)
        For Each myfolder As String In strDirs
            Dim oldName As String = myfolder.ToString
            Dim newName As String = myfolder.Replace("#", "No")
            Directory.Move(oldName, newName)
        Next
0
 
RamanaChoudaryCommented:
@DrWeb02:
umm too bad...
you used my code.. but not shared the points...
0
 
DrWeb02Author Commented:
Oops. Sorry. I'm new to this. I'll be sure to do that next time and thanks for your help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now