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.1k 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 Offline
    R Offline
    RahibeMeryem
    wrote on 20 Nov 2019, 17:51 last edited by
    #1

    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 2 Replies Last reply 20 Nov 2019, 18:15
    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 Offline
      J Offline
      JonB
      wrote on 20 Nov 2019, 18:15 last edited by
      #2

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

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

      As it stands copied from your post, this would not even compile. So it's not possible to know what you intended?

      I have never used Mac, but I thought it had a Linux file/pathname syntax, so I don't know what you mean about the problem with spaces. What do you mean about "readable format in linux"?

      Unless someone else knows what this issue is about, you might like to explain just what sort of problem you are having?

      1 Reply Last reply
      1
      • R Offline
        R Offline
        RahibeMeryem
        wrote on 20 Nov 2019, 19:03 last edited by
        #3

        @JonB

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

        This can be read by Qt QFile (file)

        but in Linux there is space problem.

        I mean that.

        J 1 Reply Last reply 20 Nov 2019, 19:12
        0
        • R RahibeMeryem
          20 Nov 2019, 19:03

          @JonB

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

          This can be read by Qt QFile (file)

          but in Linux there is space problem.

          I mean that.

          J Offline
          J Offline
          JonB
          wrote on 20 Nov 2019, 19:12 last edited by JonB
          #4

          @RahibeMeryem

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

          but in Linux there is space problem.

          No, there isn't. If that path exists on a Linux file system, QFile() will be able to open/read it.

          But if it's not there, it won't. You do have that directory, /Users/xxx/test dene bir, on your Linux box, don't you?

          What exactly is the problem?

          1 Reply Last reply
          4
          • K Offline
            K Offline
            Kent-Dorfman
            wrote on 21 Nov 2019, 04:08 last edited by
            #5

            I'd suggest using perl to rename the files in question, replacing spaces with underscores...and as a I policy I prohibit folks from ever putting spaces in filenames. It's bad practice in any platform.

            #! /usr/bin/perl
            
            $q="\x22";
            
            while (<STDIN>) {
                chomp;
                $o=$_;
                s/[\x00-\x2a]//g;
                s/[\x5b-\x5e]//g;
                s/[\x7b-\x7f]//g;
                s/\x60//g;
                s/\x2f//g;
                ($_ ne $o) && system "mv $q$o$q $q$_$q\n";
            };
            
            

            then ls | remove_spaces.pl

            J 1 Reply Last reply 21 Nov 2019, 08:43
            2
            • K Kent-Dorfman
              21 Nov 2019, 04:08

              I'd suggest using perl to rename the files in question, replacing spaces with underscores...and as a I policy I prohibit folks from ever putting spaces in filenames. It's bad practice in any platform.

              #! /usr/bin/perl
              
              $q="\x22";
              
              while (<STDIN>) {
                  chomp;
                  $o=$_;
                  s/[\x00-\x2a]//g;
                  s/[\x5b-\x5e]//g;
                  s/[\x7b-\x7f]//g;
                  s/\x60//g;
                  s/\x2f//g;
                  ($_ ne $o) && system "mv $q$o$q $q$_$q\n";
              };
              
              

              then ls | remove_spaces.pl

              J Offline
              J Offline
              JonB
              wrote on 21 Nov 2019, 08:43 last edited by JonB
              #6

              @Kent-Dorfman

              • Why would you take a Mac name with spaces in it and replace for Linux? In the sense of the OP says the spaces "work" under MacOs but "don't work" under Linux? It may be a convention that Mac often has directories/files with spaces in their names (I don't know) whereas Linux tends not to, but that's a different matter.

              • as a I policy I prohibit folks from ever putting spaces in filenames. It's bad practice in any platform.

              Sorry, but that's just wrong [EDIT: IMHO] --- we may or may not like it, but Windows uses spaces extensively and it is not "bad practice" under Windows, it's standard practice! If your app chooses to prevent creating files with spaces that's up to you, but you can't call it "bad practice" under Windows :)

              J 1 Reply Last reply 21 Nov 2019, 08:45
              0
              • J JonB
                21 Nov 2019, 08:43

                @Kent-Dorfman

                • Why would you take a Mac name with spaces in it and replace for Linux? In the sense of the OP says the spaces "work" under MacOs but "don't work" under Linux? It may be a convention that Mac often has directories/files with spaces in their names (I don't know) whereas Linux tends not to, but that's a different matter.

                • as a I policy I prohibit folks from ever putting spaces in filenames. It's bad practice in any platform.

                Sorry, but that's just wrong [EDIT: IMHO] --- we may or may not like it, but Windows uses spaces extensively and it is not "bad practice" under Windows, it's standard practice! If your app chooses to prevent creating files with spaces that's up to you, but you can't call it "bad practice" under Windows :)

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 21 Nov 2019, 08:45 last edited by
                #7

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

                it's standard practice!

                and it causes many issues, you can find examples in this forum :-)
                That's why I avoid spaces in paths and suggest others to do the same.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                J 1 Reply Last reply 21 Nov 2019, 08:49
                1
                • J jsulm
                  21 Nov 2019, 08:45

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

                  it's standard practice!

                  and it causes many issues, you can find examples in this forum :-)
                  That's why I avoid spaces in paths and suggest others to do the same.

                  J Offline
                  J Offline
                  JonB
                  wrote on 21 Nov 2019, 08:49 last edited by
                  #8

                  @jsulm
                  Yes it causes issues. The question is whether it is "bad practice" given that there a billions of Windows files around the world with spaces in them. Windows uses both directories & file names with spaces in them extensively, whether you or I like it or not. And I'll say one thing: your app may choose not to create thing with spaces because of the coding problems, but if you don't allow for existing things having spaces in them under Windows because you don't believe in it, that is where the problems will arise!

                  J 1 Reply Last reply 21 Nov 2019, 09:24
                  0
                  • J JonB
                    21 Nov 2019, 08:49

                    @jsulm
                    Yes it causes issues. The question is whether it is "bad practice" given that there a billions of Windows files around the world with spaces in them. Windows uses both directories & file names with spaces in them extensively, whether you or I like it or not. And I'll say one thing: your app may choose not to create thing with spaces because of the coding problems, but if you don't allow for existing things having spaces in them under Windows because you don't believe in it, that is where the problems will arise!

                    J Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 21 Nov 2019, 09:24 last edited by
                    #9

                    @JonB Hold the horses ;)

                    Windows also allows you to have umlaute in the path/name, and that can cause even under windows problems.

                    Just because Windows allows it doesn't mean its not bad practice.


                    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 21 Nov 2019, 09:41
                    0
                    • J J.Hilk
                      21 Nov 2019, 09:24

                      @JonB Hold the horses ;)

                      Windows also allows you to have umlaute in the path/name, and that can cause even under windows problems.

                      Just because Windows allows it doesn't mean its not bad practice.

                      J Offline
                      J Offline
                      JonB
                      wrote on 21 Nov 2019, 09:41 last edited by
                      #10

                      @J-Hilk
                      I admit I don't know about umlauts.

                      Under Windows, if you don't want to deal with spaces in path/file names, try accepting the default save file name from a new Word document, or try Ctrl+C, Ctrl+V from File Explorer, or try right-click New>Folder, or try executing anything from standard C:\Program Files\... from the command line, or use the standard Save File dialog to get a name from the user, or a million other cases.

                      So you're going to say all of these are bad practice under Windows. I don't think we'll get anywhere, because we must have different definitions of "bad practice".

                      J 1 Reply Last reply 21 Nov 2019, 10:26
                      0
                      • J JonB
                        21 Nov 2019, 09:41

                        @J-Hilk
                        I admit I don't know about umlauts.

                        Under Windows, if you don't want to deal with spaces in path/file names, try accepting the default save file name from a new Word document, or try Ctrl+C, Ctrl+V from File Explorer, or try right-click New>Folder, or try executing anything from standard C:\Program Files\... from the command line, or use the standard Save File dialog to get a name from the user, or a million other cases.

                        So you're going to say all of these are bad practice under Windows. I don't think we'll get anywhere, because we must have different definitions of "bad practice".

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 21 Nov 2019, 10:26 last edited by
                        #11

                        @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.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        J 1 Reply Last reply 22 Nov 2019, 10:48
                        1
                        • R Offline
                          R Offline
                          RahibeMeryem
                          wrote on 21 Nov 2019, 15:28 last edited by
                          #12

                          @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

                          J S K 3 Replies Last reply 21 Nov 2019, 15:34
                          0
                          • 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

                            J Offline
                            J Offline
                            JonB
                            wrote on 21 Nov 2019, 15:34 last edited by JonB
                            #13

                            @RahibeMeryem
                            My Ubuntu 19.04, I have to use Python+PySide2 instead of C++ but no matter:

                            (py37) jon@ubuntu-19:~$ mkdir "test space"
                            (py37) jon@ubuntu-19:~$ echo hello > "test space/file"
                            (py37) jon@ubuntu-19:~$ python3
                            Python 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 21:52:21) 
                            [GCC 7.3.0] :: Anaconda, Inc. on linux
                            Type "help", "copyright", "credits" or "license" for more information.
                            >>> from PySide2.QtCore import QFile
                            >>> print(QFile("test space/file").exists())
                            True
                            >>> print(QFile("test space/file").size())
                            6
                            >>> print(hex(int(QFile("test space/file").permissions())))
                            0x6644
                            >>> 
                            
                            1 Reply Last reply
                            0
                            • 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 Offline
                                    J Offline
                                    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 Offline
                                        J Offline
                                        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 Offline
                                          J Offline
                                          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

                                          7/29

                                          21 Nov 2019, 08:45

                                          22 unread
                                          • Login

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