• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • 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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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