Results 1 to 12 of 12

Thread: rename file name

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: rename file name

    Thk u for your answer.

    I have used static implementation of rename,problem still exists.

    I want to modify some contents of a text file,and do as follows:
    1.open the text file(a.txt),and read the contents of it and modify some of it.
    2.write the modified contents in a new file(b.txt);
    3.delete a.txt
    4.rename b.txt to a.txt.

    now rename can not work properly,what other ways should I go?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: rename file name

    Try using absolute paths for renaming...
    Also do you have rights to change file names on your system ?

  3. #3
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: rename file name

    Quote Originally Posted by weixj2003ld View Post
    I want to modify some contents of a text file,and do as follows:
    1.open the text file(a.txt),and read the contents of it and modify some of it.
    2.write the modified contents in a new file(b.txt);
    3.delete a.txt
    4.rename b.txt to a.txt.?
    Do you have a specific reason for doing all these steps? If you:

    1. open the file
    2. read in the data
    3. close the file
    4. change the bits you want to change
    5. re-open the file (but for writing this time)
    6. write the the new data

    this should write over all the old data. That way you don't have to worry about changing the name at all.

Similar Threads

  1. File rename detection
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 23rd July 2009, 15:22
  2. QFile::rename()
    By Bagstone in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 10:53
  3. How I add rename in QTreeWidgetItem?
    By rajesh in forum Qt Programming
    Replies: 5
    Last Post: 30th March 2007, 12:10
  4. How to rename a file after opening ?
    By npc in forum Newbie
    Replies: 2
    Last Post: 1st June 2006, 13:36

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.