Long to Short pathnames without p/invoke

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    Long to Short pathnames without p/invoke

    Does anyone know how to get a file's short pathname in 3.5? (Without p/invoke)

    I've got a file compare routine that runs a diff on two directories returning the differences of every file (attributes, times, permissions, crc etc) in the tree below the two roots.

    Now, if the file structure is too deep, my app can't get at the files. Obviously I can't just take the first 6 chars and append ~1 because of potential duplication of short folder/file names.

    I've found numerous old ways of doing this using p/invoke - but I detest using p/invoke unless there's absolutely no other choice.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Win32 API is the only way I've seen to do this, myself.

    Comment

    • balabaster
      Recognized Expert Contributor
      • Mar 2007
      • 798

      #3
      Originally posted by insertAlias
      Win32 API is the only way I've seen to do this, myself.
      Grrr, I was hoping not to hear that...

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        How deep can the file structure go before the .NET calls stop working?
        I don't think I have ever run into this?

        Comment

        • balabaster
          Recognized Expert Contributor
          • Mar 2007
          • 798

          #5
          Originally posted by Plater
          How deep can the file structure go before the .NET calls stop working?
          I don't think I have ever run into this?
          According to this document:

          Initializes a new instance of the FileInfo class, which acts as a wrapper for a file path.


          No more than 248 chars for the path length and no more than 260 chars for the file name length.

          Now, doesn't the path include the file name? If so, wouldn't a file that's got a name containing 260 chars automatically fail the 248 char length of the path? After all, even if it's in the root directory on a drive that's 3 extra chars pushing the path to 263?

          I assume it must mean that the path name is only considered as the path to the directory that contains the file. It seems to me that decision was short sighted. There's far more potential to have a longer path name than 248 chars than there is having a file name with anywhere close to 260 chars. If someone handed me a file that was named something that long, the first thing I'd do would be rename it!

          It just screams "I didn't know what to call this file, so I sat and thought about it for a while and came up with nothing, so I'm just going to name it this.txt"

          Comment

          Working...