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 ?
Forum Updated to NodeBB v4.3 + New Features

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 378 Views 1 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on 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 ?

    JonBJ 1 Reply Last reply
    0
    • Q Qt embedded developer

      @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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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....

      Christian EhrlicherC 1 Reply Last reply
      4
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 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
        1
        • Christian EhrlicherC Christian Ehrlicher

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

          JonBJ 1 Reply Last reply
          0
          • Q Qt embedded developer

            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 ?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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

              @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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 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....

              Christian EhrlicherC 1 Reply Last reply
              4
              • JonBJ JonB

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

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 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
                • Kent-DorfmanK Offline
                  Kent-DorfmanK Offline
                  Kent-Dorfman
                  wrote on 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

                  • Login

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