Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. file name change to unix file with escaping
Forum Updated to NodeBB v4.3 + New Features

file name change to unix file with escaping

Scheduled Pinned Locked Moved Unsolved General and Desktop
29 Posts 9 Posters 4.2k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R RahibeMeryem
    21 Nov 2019, 15:28

    @JonB

    yes there is directory and file as below.

    Linux path : file = "/Users/xxx/test dene biri/adf.jpg"
    
    

    QFile("/Users/xxx/test dene biri/adf.jpg") . gives error under ubuntu 19.

    I will double check tonight

    S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 21 Nov 2019, 16:08 last edited by SGaist
    #14

    @RahibeMeryem said in file name change to unix file with escaping:

    @JonB

    yes there is directory and file as below.

    Linux path : file = "/Users/xxx/test dene biri/adf.jpg"
    
    

    QFile("/Users/xxx/test dene biri/adf.jpg") . gives error under ubuntu 19.

    I will double check tonight

    Hi,

    Maybe because there's no /Users folder on Linux.

    The home folder for users under Linux is /home.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    3
    • R RahibeMeryem
      21 Nov 2019, 15:28

      @JonB

      yes there is directory and file as below.

      Linux path : file = "/Users/xxx/test dene biri/adf.jpg"
      
      

      QFile("/Users/xxx/test dene biri/adf.jpg") . gives error under ubuntu 19.

      I will double check tonight

      K Offline
      K Offline
      KroMignon
      wrote on 21 Nov 2019, 16:14 last edited by
      #15

      @RahibeMeryem said in file name change to unix file with escaping:

      yes there is directory and file as below.
      Linux path : file = "/Users/xxx/test dene biri/adf.jpg"

      QFile("/Users/xxx/test dene biri/adf.jpg") . gives error under ubuntu 19.

      On Linux/Unix systems, if you want to access to an user directory, it is preferable to use '~', for example for user foo: QFile("~foo/test dene biri/adf.jpg")

      I don't know if on macOS this is also working.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 21 Nov 2019, 16:16 last edited by
        #16

        @KroMignon that's a shell shortcut so it may or may not work depending on what you are doing.
        Using QStandardPaths would be better.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        K 1 Reply Last reply 24 Nov 2019, 23:36
        6
        • J Online
          J Online
          JonB
          wrote on 21 Nov 2019, 16:44 last edited by JonB
          #17

          But I have asked and the OP confirmed:

          yes there is directory and file as below.

          Linux path : file = "/Users/xxx/test dene biri/adf.jpg"

          So he must have checked that on his Linux he has a /Users/..., for whatever reason. He says the issue is to do with the spaces.

          K 1 Reply Last reply 21 Nov 2019, 17:15
          0
          • J JonB
            21 Nov 2019, 16:44

            But I have asked and the OP confirmed:

            yes there is directory and file as below.

            Linux path : file = "/Users/xxx/test dene biri/adf.jpg"

            So he must have checked that on his Linux he has a /Users/..., for whatever reason. He says the issue is to do with the spaces.

            K Offline
            K Offline
            KroMignon
            wrote on 21 Nov 2019, 17:15 last edited by KroMignon
            #18

            @JonB said in file name change to unix file with escaping:

            for whatever reason

            @RahibeMeryem Did you check if the application has read/excecute rights for each sub-directory?

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            J 1 Reply Last reply 21 Nov 2019, 17:22
            0
            • K KroMignon
              21 Nov 2019, 17:15

              @JonB said in file name change to unix file with escaping:

              for whatever reason

              @RahibeMeryem Did you check if the application has read/excecute rights for each sub-directory?

              J Online
              J Online
              JonB
              wrote on 21 Nov 2019, 17:22 last edited by
              #19

              @KroMignon Why are you directing this question to me?

              1 Reply Last reply
              0
              • R RahibeMeryem
                20 Nov 2019, 17:51

                Hi,

                I developed my app in Mac and when I transfer to the linux there is qfile file read problem due to some of the file and dirs has " " spaces.

                I try to QString.replace(" " , "\" ) and looks replaced .

                but even I saw the file name escaped with \ in linux , it says cant find the name.

                is there any best practices to change file name to readable format in linux ?

                J Online
                J Online
                JonB
                wrote on 21 Nov 2019, 17:42 last edited by JonB
                #20

                @RahibeMeryem
                OK, this is bugging me :) So here is a list of steps which will resolve where we are on this issue.

                If you know how to open a terminal/shell/command-prompt-window on Ubuntu:

                1. Open a terminal/shell/command-prompt-window. (Do not type sudo anything, if you might be tempted to.)
                2. Type ls -b /Users
                3. Then ls -b /Users/xxx, with whatever for the xxx
                4. Then ls -b /Users/xxx/test dene biri
                5. Finallyls -b /Users/xxx/test dene biri/adf.jpg
                6. If you really get as far as here without a "No such file or directory"-type error, type ls -l /Users/xxx/test dene biri/adf.jpg
                7. Copy the output you get as you go along and paste it here.

                If you do not know how to open a terminal:

                1. Open the "File Explorer" from its icon on the desktop
                2. Make it browse to the top-level root directory, named /.
                3. Go downwards into directories/folders for your path, i.e. Users, then whatever for the xxx, then test dene biri.
                4. Show us a screenshot (screenshot program, https://help.ubuntu.com/stable/ubuntu-help/screen-shot-record.html) of where you get to.

                P.S.
                I just noticed there is some confusion of whether the path has test dene bir or test dene biri (the extra i at the end) in some of these posts. I may have introduced that inadvertently. Obviously ensure both Mac & Linux code use whichever spelling is correct for you.

                1 Reply Last reply
                1
                • R Offline
                  R Offline
                  RahibeMeryem
                  wrote on 22 Nov 2019, 08:56 last edited by
                  #21

                  @JonB @SGaist

                  I found the STUPiD problem or a bug:

                  one of my folder path include 'ü' . utf8 character with spaces.

                  the 'ü' is different between mac os x and linux . in the linux ls -l look %100 identical but its not.

                  so I create same folder name with linux 'ü' its working now.

                  suprise.

                  J 1 Reply Last reply 22 Nov 2019, 09:59
                  0
                  • R RahibeMeryem
                    22 Nov 2019, 08:56

                    @JonB @SGaist

                    I found the STUPiD problem or a bug:

                    one of my folder path include 'ü' . utf8 character with spaces.

                    the 'ü' is different between mac os x and linux . in the linux ls -l look %100 identical but its not.

                    so I create same folder name with linux 'ü' its working now.

                    suprise.

                    J Online
                    J Online
                    JonB
                    wrote on 22 Nov 2019, 09:59 last edited by JonB
                    #22

                    @RahibeMeryem

                    in the linux ls -l look %100 identical but its not.

                    That is precisely why you will see I suggested you use ls -b in all my examples, which I guess is how you spotted it....

                    1 Reply Last reply
                    1
                    • J jsulm
                      21 Nov 2019, 10:26

                      @JonB said in file name change to unix file with escaping:

                      So you're going to say all of these are bad practice under Windows

                      Using existing system directories with spaces is not bad practice. But using own directories/file names with spaces (or umlauts) is at least questionable. I try to avoid this.

                      J Online
                      J Online
                      J.Hilk
                      Moderators
                      wrote on 22 Nov 2019, 10:48 last edited by
                      #23

                      @RahibeMeryem said in file name change to unix file with escaping:

                      @JonB @SGaist

                      I found the STUPiD problem or a bug:

                      one of my folder path include 'ü' . utf8 character with spaces.

                      the 'ü' is different between mac os x and linux . in the linux ls -l look %100 identical but its not.

                      so I create same folder name with linux 'ü' its working now.

                      suprise.

                      Ah, we went full circle, let me quote:

                      @jsulm said in file name change to unix file with escaping:

                      @JonB said in file name change to unix file with escaping:

                      So you're going to say all of these are bad practice under Windows

                      Using existing system directories with spaces is not bad practice. But using own directories/file names with spaces (or umlauts) is at least questionable. I try to avoid this.


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      J 1 Reply Last reply 22 Nov 2019, 11:17
                      1
                      • J J.Hilk
                        22 Nov 2019, 10:48

                        @RahibeMeryem said in file name change to unix file with escaping:

                        @JonB @SGaist

                        I found the STUPiD problem or a bug:

                        one of my folder path include 'ü' . utf8 character with spaces.

                        the 'ü' is different between mac os x and linux . in the linux ls -l look %100 identical but its not.

                        so I create same folder name with linux 'ü' its working now.

                        suprise.

                        Ah, we went full circle, let me quote:

                        @jsulm said in file name change to unix file with escaping:

                        @JonB said in file name change to unix file with escaping:

                        So you're going to say all of these are bad practice under Windows

                        Using existing system directories with spaces is not bad practice. But using own directories/file names with spaces (or umlauts) is at least questionable. I try to avoid this.

                        J Online
                        J Online
                        JonB
                        wrote on 22 Nov 2019, 11:17 last edited by JonB
                        #24

                        @J-Hilk
                        For all we know he has no choice about directory spelling. E.g. if his user name contains an umlaut he types in, I would guess Linux creates his home directory based on this. Perhaps because this is "bad practice" we'd better tell Linux to change its ways.... Or, perhaps the user should change his real name to accommodate...

                        J 1 Reply Last reply 22 Nov 2019, 11:31
                        0
                        • J JonB
                          22 Nov 2019, 11:17

                          @J-Hilk
                          For all we know he has no choice about directory spelling. E.g. if his user name contains an umlaut he types in, I would guess Linux creates his home directory based on this. Perhaps because this is "bad practice" we'd better tell Linux to change its ways.... Or, perhaps the user should change his real name to accommodate...

                          J Online
                          J Online
                          J.Hilk
                          Moderators
                          wrote on 22 Nov 2019, 11:31 last edited by
                          #25

                          @JonB said in file name change to unix file with escaping:

                          Or, perhaps the user should change his real name to accommodate...

                          yep, that's what I did at my old work place,
                          ü -> ue


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          A 1 Reply Last reply 22 Nov 2019, 11:36
                          0
                          • J J.Hilk
                            22 Nov 2019, 11:31

                            @JonB said in file name change to unix file with escaping:

                            Or, perhaps the user should change his real name to accommodate...

                            yep, that's what I did at my old work place,
                            ü -> ue

                            A Offline
                            A Offline
                            artwaw
                            wrote on 22 Nov 2019, 11:36 last edited by
                            #26

                            @J-Hilk a bit OT but touches the good/bad practice part: in my workplace we have around 20 nationalities using 4 or 5 different alphabets. All the names and surnames in the sysaccounts/paths are transliterated to English exactly to avoid problems like that.

                            For more information please re-read.

                            Kind Regards,
                            Artur

                            1 Reply Last reply
                            4
                            • M Offline
                              M Offline
                              mpergand
                              wrote on 22 Nov 2019, 13:13 last edited by mpergand
                              #27

                              This vicious bug is due to the fact that Mac file system uses a special variant of unicode called decomposed form (NFD)
                              see https://developer.apple.com/library/archive/qa/qa1235/_index.html

                              However, you may need to convert to precomposed Unicode when you interact with other platforms.
                              For example, the following are all valid reasons why you might want to convert to precomposed Unicode:
                              -If you implement a network protocol which is defined to use precomposed Unicode.
                              -When creating a cross-platform file (or volume) whose specification dictates precomposed Unicode.
                              -If you incorporate a large body of cross-platform code into your application,
                              where that code is expecting precomposed Unicode.

                              For the same reason, if you're using C/C++ libraries that deal with file paths, it's advisable to use the following method for converting QString to *char:
                              [filePath.toNSString() fileSystemRepresentation];

                              1 Reply Last reply
                              2
                              • S SGaist
                                21 Nov 2019, 16:16

                                @KroMignon that's a shell shortcut so it may or may not work depending on what you are doing.
                                Using QStandardPaths would be better.

                                K Offline
                                K Offline
                                Kent-Dorfman
                                wrote on 24 Nov 2019, 23:36 last edited by
                                #28

                                @SGaist

                                @SGaist said in file name change to unix file with escaping:

                                @KroMignon that's a shell shortcut so it may or may not work depending on what you are doing.
                                Using QStandardPaths would be better.

                                Yes, tilde is a shell shortcut, so should only ever be used in immediate mode on the command line in shells that recognize it. Use anywhere else can and probably will fail to be interpreted properly.

                                J 1 Reply Last reply 25 Nov 2019, 09:14
                                1
                                • K Kent-Dorfman
                                  24 Nov 2019, 23:36

                                  @SGaist

                                  @SGaist said in file name change to unix file with escaping:

                                  @KroMignon that's a shell shortcut so it may or may not work depending on what you are doing.
                                  Using QStandardPaths would be better.

                                  Yes, tilde is a shell shortcut, so should only ever be used in immediate mode on the command line in shells that recognize it. Use anywhere else can and probably will fail to be interpreted properly.

                                  J Online
                                  J Online
                                  JonB
                                  wrote on 25 Nov 2019, 09:14 last edited by JonB
                                  #29

                                  @Kent-Dorfman
                                  Hence @SGaist's comment that you would hardly ever want to construct a QFile("~...") anything. The only times would be for path-splitting function calls (even then be careful, e.g. Qt will think it's a relative path when in effect it's actually absolute), or to convert directly to string for passing to an OS command. Any other operations like trying to open it will not address the intended file (e.g. https://stackoverflow.com/questions/2816499/why-cant-qfile-read-from-the-directory).

                                  1 Reply Last reply
                                  0

                                  23/29

                                  22 Nov 2019, 10:48

                                  • Login

                                  • Login or register to search.
                                  23 out of 29
                                  • First post
                                    23/29
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved