DirectoryInfo.Exists fails with copyright symbol

Posted on 2011-10-14
Medium Priority
Last Modified: 2012-05-12
I have a vb .net batch application to process a text list of directory names

Some of these names contain ASCII character 63 (the copyright symbol). This isn't under my control and I need to parse the text following the symbol as well as process the folder contents

strPath = mystream.Readline
MyDir = New DirectoryInfo(strPath)

this fails even when a folder with this name exists

How can I en/decode the text so that the Directoryinfo is created for these folders?
Question by:czwg
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36969280
I got it to work by opening the file with UTF7 encoding:

    Dim mystream As New System.IO.StreamReader(FileName, System.Text.Encoding.UTF7)

© = Alt-0169 (on your keypad)
LVL 40

Accepted Solution

Jacques Bourgeois (James Burger) earned 375 total points
ID: 36969741
Look at the content of strPath after reading it from your stream. Replace the faulty character by a © as I do in the following, where I am expecting to get C:\test©test
Dim strpath As String = "C:\test¶test"
strpath = strpath.Replace("¶", "©")

Open in new window


Author Closing Comment

ID: 37000057
This is what I did in the end. It wasn't the elegant and robust solution I had been hoping for - every other non alphanumeric character that may exist in folder names may require a replace operation. Fortunately among the 200 or so folders, I don't think there are any others.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

839 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