Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-09-2009, 05:30 AM   #1
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 151

Rep: Reputation: 15
rename oldfile to newfile only if newfile does not exist

Is there any command to use in c++ on linux platform for renaming oldfile to newfile only if newfile does not exist. If newfile exist it must return some error no.
In windows rename() is used , but in linux it will automatically replaced even though newpath already exists.

Nagendra R.
Old 09-09-2009, 06:27 AM   #2
Registered: Nov 2007
Location: /home/watcher69b
Distribution: RH, Fedora & CentOS
Posts: 544

Rep: Reputation: 40
or perhaps your program can rename the file before it beings its run, like when you are 1st defining variables. If there is no file then the program should just move on.
something like "mv -f /var/log/bob /var/log/bob.OLD" the -f (force) will keep it from stalling your program.

or you can always append the file with the >>


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
cat onelinefile.txt >> newfile.txt; cat twofile.txt >> newfile.txt keep newline? tmcguinness Programming 4 02-12-2009 06:38 AM
rename errorsunknownp Linux - Newbie 2 12-28-2008 05:06 AM
rename a distro? geeyathink General 12 05-08-2007 06:20 AM
Rename my pc ? Tanc Linux - Newbie 6 09-13-2003 08:28 AM
how can I rename my computer ? tied2 Linux - General 6 09-04-2002 08:12 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration