Results 1 to 3 of 3

Thread: How to Create file but if name exists add incremental number to file name

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Mar 2021
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to Create file but if name exists add incremental number to file name

    You can check if the file exists using QFile::exists(filename) and if yes, you can add to the new file a new name.
    Qt Code:
    1. QString new_file(“Qtfile.txt);
    2. if(QFile::exists(new_file) {
    3. new_file = “Qtfile.txt1.txt);
    4. }
    To copy to clipboard, switch view to plain text mode 
    And then create the file
    Last edited by d_stranz; 26th March 2021 at 15:32. Reason: missing [code] tags

Similar Threads

  1. Appending data, if file exists.
    By rookee in forum Newbie
    Replies: 1
    Last Post: 10th December 2015, 15:11
  2. File exists even if it should have deleted
    By davidlamhauge in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2014, 02:28
  3. File exists on server
    By Chops211 in forum Qt Programming
    Replies: 5
    Last Post: 6th August 2011, 20:22
  4. Replies: 2
    Last Post: 21st February 2011, 14:52
  5. Can't create folder if file with same name exists
    By Barry79 in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2009, 16:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.