Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 973595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:18:09+00:00 2026-05-16T03:18:09+00:00

I have a directory that ends with a period (.), created by rsync via

  • 0

I have a directory that ends with a period (.), created by rsync via Cygwin on a Windows server.

The code I have tries to read a file inside this directory but I get an exception saying that it “Could not find a part of the path” and the ending period is missing from the path the program tries to read.

Is it possible to read directories ending in a period via C#?

Thank you for any help.

Code beeing used:

StreamReader sr = null;
try
  {
    sr = new StreamReader(@"<path_ending_in_period>", System.Text.Encoding.Default);
  }
catch (Exception ex)
  {
            ....
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:18:09+00:00Added an answer on May 16, 2026 at 3:18 am

    Check the Test() method below. It has examples for both local and UNC path, and works with files ending in a dot. The code is based on the code found at Link, which also has code for deleting the file.

    Basically you get a FileHandle from the Win32 API, and pass it on to .Net.

    [Edit – new code]

    using System;
    using System.ComponentModel;
    using System.IO;
    using System.Runtime.InteropServices;
    using Microsoft.Win32.SafeHandles;
    
    namespace ConsoleApplication1
    {
        internal class WeirdFilename
        {
            public static void Test()
            {
                //string formattedName = @"\\?\c:\temp\dot.";
                string formattedName = @"\\?\UNC\m1330\c$\temp\dot.";
                SafeFileHandle fileHandle = CreateFile(formattedName,
                                                        EFileAccess.GenericRead, EFileShare.None, IntPtr.Zero,
                                                        ECreationDisposition.OpenExisting, 0, IntPtr.Zero);
    
                // Check for errors
                int lastWin32Error = Marshal.GetLastWin32Error();
                if (fileHandle.IsInvalid)
                {
                    throw new Win32Exception(lastWin32Error);
                }
    
                // Pass the file handle to FileStream. FileStream will close the handle
                using (FileStream fs = new FileStream(fileHandle, FileAccess.Read))
                {
                    StreamReader reader = new StreamReader(fs);
                }
            }
    
    
            #region ECreationDisposition enum
    
            public enum ECreationDisposition : uint
            {
                New = 1,
                CreateAlways = 2,
                OpenExisting = 3,
                OpenAlways = 4,
                TruncateExisting = 5,
            }
    
            #endregion
    
            #region EFileAccess enum
    
            [Flags]
            public enum EFileAccess : uint
            {
                GenericRead = 0x80000000,
                GenericWrite = 0x40000000,
                GenericExecute = 0x20000000,
                GenericAll = 0x10000000,
            }
    
            #endregion
    
            #region EFileAttributes enum
    
            [Flags]
            public enum EFileAttributes : uint
            {
                Readonly = 0x00000001,
                Hidden = 0x00000002,
                System = 0x00000004,
                Directory = 0x00000010,
                Archive = 0x00000020,
                Device = 0x00000040,
                Normal = 0x00000080,
                Temporary = 0x00000100,
                SparseFile = 0x00000200,
                ReparsePoint = 0x00000400,
                Compressed = 0x00000800,
                Offline = 0x00001000,
                NotContentIndexed = 0x00002000,
                Encrypted = 0x00004000,
                Write_Through = 0x80000000,
                Overlapped = 0x40000000,
                NoBuffering = 0x20000000,
                RandomAccess = 0x10000000,
                SequentialScan = 0x08000000,
                DeleteOnClose = 0x04000000,
                BackupSemantics = 0x02000000,
                PosixSemantics = 0x01000000,
                OpenReparsePoint = 0x00200000,
                OpenNoRecall = 0x00100000,
                FirstPipeInstance = 0x00080000
            }
    
            #endregion
    
            #region EFileShare enum
    
            [Flags]
            public enum EFileShare : uint
            {
                None = 0x00000000,
                Read = 0x00000001,
                Write = 0x00000002,
                Delete = 0x00000004,
            }
    
            #endregion
    
            [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            internal static extern SafeFileHandle CreateFile(
                string lpFileName,
                EFileAccess dwDesiredAccess,
                EFileShare dwShareMode,
                IntPtr lpSecurityAttributes,
                ECreationDisposition dwCreationDisposition,
                EFileAttributes dwFlagsAndAttributes,
                IntPtr hTemplateFile);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directory of files that I'd like to append file extension to
In the filesystem I have /file.aspx /directory/default.aspx I want to configure IIS so that
I have a mercurial repository, and inside it a file that ends with '>>'.
I just started using SVN, and I have a cache directory that I don't
I have a directory of bitmaps that are all of the same dimension. I
I have a directory of files that I would like to scan on a
I have XML files in a directory that I wish to get over to
I have a directory with PDF files that I need to create an index
I have a directory on a linux box that I want to make publicly
We have several .NET applications that monitor a directory for new files, using FileSystemWatcher.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.