File.Exists case change

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sweetiecakes

    File.Exists case change

    In our series of "probably something simple"...

    I am doing a File.Exists operation to check if a file exists. Let's
    assume that this file is C:/test.txt.

    Now, if I do File.Exists("C: \\Test.txt"), I do not want it to tell me
    that the file exists - this is a check for a File.Move operation (some
    file renaming functionality). But if I check C:\\test.txt, it should
    return true.

    Any suggestions?
  • DH

    #2
    Re: File.Exists case change

    Sweetiecakes wrote:
    In our series of "probably something simple"...
    >
    I am doing a File.Exists operation to check if a file exists. Let's
    assume that this file is C:/test.txt.
    >
    Now, if I do File.Exists("C: \\Test.txt"), I do not want it to tell me
    that the file exists - this is a check for a File.Move operation (some
    file renaming functionality). But if I check C:\\test.txt, it should
    return true.
    >
    Any suggestions?
    Sweetiecakes,
    the question does not make mush sense you are saying you dont want it to
    tel you if the file esists but the it should return true;
    File.Exists() returns a boolean (true or false) if the file exists it
    returns true otherwise false.

    if you want to check a folder to make sure a file with that name does
    not exist you could do:
    if(!File.Exists (destpath)){
    //move
    }
    else{
    //do whatever you want
    }

    Comment

    • Sweetiecakes

      #3
      Re: File.Exists case change

      DH wrote:
      Sweetiecakes,
      the question does not make mush sense you are saying you dont want it to
      tel you if the file esists but the it should return true;
      File.Exists() returns a boolean (true or false) if the file exists it
      returns true otherwise false.
      >
      if you want to check a folder to make sure a file with that name does
      not exist you could do:
      if(!File.Exists (destpath)){
      //move
      }
      else{
      //do whatever you want
      }
      I don't know what I've been typing in my last message - but basically,
      what I meant, was that I want the File.Exists() command to be
      _case-sensitive_, so that test.txt and Test.txt are not the same thing
      (such as in an Unix environment).

      Thanks

      Comment

      • Sweetiecakes

        #4
        Re: File.Exists case change

        I don't know what I've been typing in my last message - but basically,
        what I meant, was that I want the File.Exists() command to be
        _case-sensitive_, so that test.txt and Test.txt are not the same thing
        (such as in an Unix environment).

        Thanks

        Comment

        • DH

          #5
          Re: File.Exists case change

          Sweetiecakes wrote:
          DH wrote:
          >Sweetiecakes ,
          >the question does not make mush sense you are saying you dont want it
          >to tel you if the file esists but the it should return true;
          >File.Exists( ) returns a boolean (true or false) if the file exists it
          >returns true otherwise false.
          >>
          >if you want to check a folder to make sure a file with that name does
          >not exist you could do:
          >if(!File.Exist s(destpath)){
          >//move
          >}
          >else{
          >//do whatever you want
          >}
          >
          I don't know what I've been typing in my last message - but basically,
          what I meant, was that I want the File.Exists() command to be
          _case-sensitive_, so that test.txt and Test.txt are not the same thing
          (such as in an Unix environment).
          >
          Thanks
          That is not going to be possible in a windows environment. In windows
          test.txt and Test.txt are the same thing. so unless ur using a *nix
          environment in windows you will never have test.txt and Test.txt in the
          same directory.

          Comment

          • Jeff Johnson

            #6
            Re: File.Exists case change

            "Sweetiecak es" <x@x.comwrote in message
            news:491df6aa$0 $20331$9b536df3 @news.fv.fi...
            I don't know what I've been typing in my last message - but basically,
            what I meant, was that I want the File.Exists() command to be
            _case-sensitive_, so that test.txt and Test.txt are not the same thing
            (such as in an Unix environment).
            I would say you should try to create a FileInfo object and then (assuming
            Exists returns true) test its Name property against your original string in
            a case-sensitive manner. This is off the top of my head, and I can't be
            positive that the FileInfo object will return the properly-cased file name
            in the Name property or if it will simply parrot what you put in, but my gut
            feeling is that you'll get the real file name. Try it.


            Comment

            • DH

              #7
              Re: File.Exists case change

              Sweetiecakes wrote:
              I don't know what I've been typing in my last message - but basically,
              what I meant, was that I want the File.Exists() command to be
              _case-sensitive_, so that test.txt and Test.txt are not the same thing
              (such as in an Unix environment).
              >
              Thanks
              I guess if you really want to make it case sensitive you could use
              Directory.GetFi les()
              and go through the files and check them but this is going to be slow and
              inefficient if the folder has a lot of files.

              Comment

              • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

                #8
                Re: File.Exists case change

                Sweetiecakes wrote:
                I don't know what I've been typing in my last message - but basically,
                what I meant, was that I want the File.Exists() command to be
                _case-sensitive_, so that test.txt and Test.txt are not the same thing
                (such as in an Unix environment).
                I am very sure that trying to use NTFS as a case sensitive file system
                will be a disaster.

                But if you insist, then try:

                public static class MyFile
                {
                public static bool MyExists(string fnm)
                {
                if(!File.Exists (fnm)) return false;
                return
                Array.Exists(Di rectory.GetFile s(Path.GetDirec toryName(fnm)), s =s ==
                Path.GetFullPat h(fnm));
                }

                }


                Arne

                Comment

                • MC

                  #9
                  Re: File.Exists case change


                  "Arne Vajhøj" <arne@vajhoej.d kwrote in message news:491e2f28$0 $90268$14726298 @news.sunsite.d k...
                  Sweetiecakes wrote:
                  >I don't know what I've been typing in my last message - but basically,
                  >what I meant, was that I want the File.Exists() command to be
                  >_case-sensitive_, so that test.txt and Test.txt are not the same thing
                  >(such as in an Unix environment).
                  I am very sure that trying to use NTFS as a case sensitive file system
                  will be a disaster.
                  Right -- to underscore that point -- Windows NTFS is *not* a case-sensitive file system and you will find discrepancies from one machine to another as to how case is handled. Under Windows, if test.txt exists, then so does Test.Txt, because they are the same file.

                  Comment

                  Working...