DirectoryInfo.Exists fails with copyright symbol

Posted on 2011-10-14
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 85

    Expert Comment

    by:Mike Tomlinson
    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

    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

    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

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now