LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 05:30 AM   #1
nagendrar
Member
 
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 154

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, 06:27 AM   #2
watcher69b
Member
 
Registered: Nov 2007
Location: /home/watcher69b
Distribution: RH, Fedora & CentOS
Posts: 552

Rep: Reputation: 41
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:49 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
Open Source Consulting | Domain Registration