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. why file copy function not working when we use the filename containing colon ?

why file copy function not working when we use the filename containing colon ?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 372 Views
  • 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on 27 Dec 2022, 09:39 last edited by
    #1

    i have seen that in my linux system that:

    when i copy file that contain name like 1227202212:10:19

    to my destination of usb pen drive it not copy the file.

    srcPath : /home/raimbow/Rtime/Can/1227202212:10:40"

    dstPath : /media/raimbow/4AFB-18C7/1227202212:10:40"

    retValue =  QFile::copy(srcPath, dstPath);
    

    my above function return false .

    what is solution to make it work ?

    J 1 Reply Last reply 27 Dec 2022, 10:26
    0
    • Q Qt embedded developer
      27 Dec 2022, 10:25

      @Christian-Ehrlicher

      i have found that when we are going to do copy in pen drive at that time this file copy function not working. i have checked it. if we replace destination file name's colon with '_' its works fine

      J Offline
      J Offline
      JonB
      wrote on 27 Dec 2022, 10:28 last edited by
      #5

      @Qt-embedded-developer said in why file copy function not working when we use the filename containing colon ?:

      i have found that when we are going to do copy in pen drive at that time this file copy function not working. i have checked it. if we replace destination file name's colon with '_' its works fine

      Well let's start with what file system your pen drive is formatted as? For example, if it's FAT32 or NTFS then I would imagine colons may be illegal in filenames, even under Linux?

      First thing is to try this outside of Qt application....

      C 1 Reply Last reply 27 Dec 2022, 11:34
      4
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 27 Dec 2022, 09:58 last edited by
        #2

        Has nothing to do with colons but with your access rights or the file arealdy exists I would guess.
        Works fine for me:

        #include <QtCore>
        
        int main(int argc, char **argv)
        {
          QCoreApplication app(argc, argv);
          QString src = "./test:1234";
          QString dst = "./test:12345";
          if (QFile::copy(src, dst)) {
            qDebug() << "Success";
          } else {
            qDebug() << "Failed";
          }
          return 0;
        }
        

        Please create minimal, compilable examples before you post your problems here.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        Q 1 Reply Last reply 27 Dec 2022, 10:25
        1
        • C Christian Ehrlicher
          27 Dec 2022, 09:58

          Has nothing to do with colons but with your access rights or the file arealdy exists I would guess.
          Works fine for me:

          #include <QtCore>
          
          int main(int argc, char **argv)
          {
            QCoreApplication app(argc, argv);
            QString src = "./test:1234";
            QString dst = "./test:12345";
            if (QFile::copy(src, dst)) {
              qDebug() << "Success";
            } else {
              qDebug() << "Failed";
            }
            return 0;
          }
          

          Please create minimal, compilable examples before you post your problems here.

          Q Offline
          Q Offline
          Qt embedded developer
          wrote on 27 Dec 2022, 10:25 last edited by
          #3

          @Christian-Ehrlicher

          i have found that when we are going to do copy in pen drive at that time this file copy function not working. i have checked it. if we replace destination file name's colon with '_' its works fine

          J 1 Reply Last reply 27 Dec 2022, 10:28
          0
          • Q Qt embedded developer
            27 Dec 2022, 09:39

            i have seen that in my linux system that:

            when i copy file that contain name like 1227202212:10:19

            to my destination of usb pen drive it not copy the file.

            srcPath : /home/raimbow/Rtime/Can/1227202212:10:40"

            dstPath : /media/raimbow/4AFB-18C7/1227202212:10:40"

            retValue =  QFile::copy(srcPath, dstPath);
            

            my above function return false .

            what is solution to make it work ?

            J Offline
            J Offline
            JonB
            wrote on 27 Dec 2022, 10:26 last edited by JonB
            #4

            @Qt-embedded-developer
            You/@Christian-Ehrlicher are using the static function bool QFile::copy(const QString &fileName, const QString &newName). When that files you don't get any information as to why.

            I assume (untested) that if you use a the instance method bool QFile::copy(const QString &newName) then when it fails you can call QFileDevice::FileError QFileDevice::error() const on the QFile to find out why?

            1 Reply Last reply
            1
            • Q Qt embedded developer
              27 Dec 2022, 10:25

              @Christian-Ehrlicher

              i have found that when we are going to do copy in pen drive at that time this file copy function not working. i have checked it. if we replace destination file name's colon with '_' its works fine

              J Offline
              J Offline
              JonB
              wrote on 27 Dec 2022, 10:28 last edited by
              #5

              @Qt-embedded-developer said in why file copy function not working when we use the filename containing colon ?:

              i have found that when we are going to do copy in pen drive at that time this file copy function not working. i have checked it. if we replace destination file name's colon with '_' its works fine

              Well let's start with what file system your pen drive is formatted as? For example, if it's FAT32 or NTFS then I would imagine colons may be illegal in filenames, even under Linux?

              First thing is to try this outside of Qt application....

              C 1 Reply Last reply 27 Dec 2022, 11:34
              4
              • J JonB
                27 Dec 2022, 10:28

                @Qt-embedded-developer said in why file copy function not working when we use the filename containing colon ?:

                i have found that when we are going to do copy in pen drive at that time this file copy function not working. i have checked it. if we replace destination file name's colon with '_' its works fine

                Well let's start with what file system your pen drive is formatted as? For example, if it's FAT32 or NTFS then I would imagine colons may be illegal in filenames, even under Linux?

                First thing is to try this outside of Qt application....

                C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 27 Dec 2022, 11:34 last edited by
                #6

                @JonB said in why file copy function not working when we use the filename containing colon ?:

                if it's FAT32 or NTFS then I would imagine colons may be illegal

                Correct

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • K Offline
                  K Offline
                  Kent-Dorfman
                  wrote on 28 Dec 2022, 12:02 last edited by
                  #7

                  And herein lies why you should "never" name files with anything but alphanumeric characters, and also avoid spaces while you're at it.

                  1 Reply Last reply
                  1

                  7/7

                  28 Dec 2022, 12:02

                  • Login

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