LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 09-09-2009, 06:30 AM   #1
nagendrar
Member
 
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 150

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.

ThankU,
Nagendra R.
 
Old 09-09-2009, 07:27 AM   #2
watcher69b
Member
 
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 >>
 
  


Reply


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 07:38 AM
rename errorsunknownp Linux - Newbie 2 12-28-2008 06:06 AM
rename a distro? geeyathink General 12 05-08-2007 07:20 AM
Rename my pc ? Tanc Linux - Newbie 6 09-13-2003 09:28 AM
how can I rename my computer ? tied2 Linux - General 6 09-04-2002 09:12 AM


All times are GMT -5. The time now is 07:06 AM.

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