<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Rename a file in C++ on Unix platform in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214058#M91775</link>
    <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; But i need a way that renames the file both in unix and windows&lt;BR /&gt;&lt;BR /&gt;use Perl;&lt;BR /&gt;&lt;BR /&gt;Write a simple Perl script using the File::Copy module.  This implements things in a platform independent fashion.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Wed, 11 Jun 2008 12:07:19 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2008-06-11T12:07:19Z</dc:date>
    <item>
      <title>Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214050#M91767</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;I have a c++ code to rename a pdf file using io.h.While trying to run the same code in unix platform it is giving error message.Is there any way to rename in c++ which is compatible to unix.Or How could i rectify this problem.Please give a suggestion&lt;BR /&gt;c++ code&lt;BR /&gt;rename(tmpfn[0], filename)&lt;BR /&gt;&lt;BR /&gt;Thanks in Advance&lt;BR /&gt;Soumya...</description>
      <pubDate>Tue, 10 Jun 2008 15:08:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214050#M91767</guid>
      <dc:creator>Soumya Krishnan</dc:creator>
      <dc:date>2008-06-10T15:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214051#M91768</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Well, 'rename()' is the Unix system call to change the name of a file (of course).&lt;BR /&gt;&lt;BR /&gt;You need to specify what "error (message)" you are getting.  You *should* be examining any 'errno' returned when the return status of the 'rename' isn't zero.  That should tell you the reason for your failure.&lt;BR /&gt;&lt;BR /&gt;I would also re-read the manapges:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/en/B3921-60631/rename.2.html" target="_blank"&gt;http://docs.hp.com/en/B3921-60631/rename.2.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;For instance, are your source and target names in the same filesystem.  If not, you can't 'rename()'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 10 Jun 2008 15:26:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214051#M91768</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-10T15:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214052#M91769</link>
      <description>Hii James,&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for your suggestion .&lt;BR /&gt;The error number i got is errno=18 &lt;BR /&gt;[EXDEV]&lt;BR /&gt;The paths named by source and target are on different logical devices (file systems).&lt;BR /&gt;What shall i do for this.&lt;BR /&gt;I am trying to rename a file from the folder&lt;BR /&gt;/var/tmp/xyz.pdf to ./Result/abc.pdf&lt;BR /&gt;means from a system temporary folder to application folder</description>
      <pubDate>Wed, 11 Jun 2008 06:22:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214052#M91769</guid>
      <dc:creator>Soumya Krishnan</dc:creator>
      <dc:date>2008-06-11T06:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214053#M91770</link>
      <description>&amp;gt; What shall i do for this.&lt;BR /&gt;&lt;BR /&gt;What would you like to do?  Many things are&lt;BR /&gt;possible.  For example:&lt;BR /&gt;&lt;BR /&gt;1) When you get EXDEV, quit.&lt;BR /&gt;&lt;BR /&gt;2) When you get EXDEV, copy the file, and&lt;BR /&gt;then, if that works, delete the original&lt;BR /&gt;file.&lt;BR /&gt;&lt;BR /&gt;3) Don't create the temporary file in&lt;BR /&gt;/var/tmp.  Instead, create it in the&lt;BR /&gt;destination directory (with some funny name),&lt;BR /&gt;and when it's ready, rename it to the&lt;BR /&gt;desired name.&lt;BR /&gt;&lt;BR /&gt;Some programs (Info-ZIP Zip, for example)&lt;BR /&gt;will try to do 3, but if the rename fails&lt;BR /&gt;for some reason, it'll try to do the job with&lt;BR /&gt;a copy.  (And if that fails, it'll complain.)</description>
      <pubDate>Wed, 11 Jun 2008 06:34:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214053#M91770</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-06-11T06:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214054#M91771</link>
      <description>&amp;gt;I am trying to rename a file from  /var/tmp/xyz.pdf to ./Result/abc.pdf&lt;BR /&gt;&lt;BR /&gt;As Steven says, you can't do that directly if not on the same filesystem.&lt;BR /&gt;&lt;BR /&gt;If you are real lazy, you can use system(3) to invoke mv(1):&lt;BR /&gt;system("mv /var/tmp/xyz.pdf ./Result/abc.pdf");&lt;BR /&gt;&lt;BR /&gt;Of course if the two files are variables, you would have to use strcpy and strcat to form the string.  Or use:&lt;BR /&gt;snprintf(buf, sizeof(buf), "mv %s %s", from_file, to_file);</description>
      <pubDate>Wed, 11 Jun 2008 07:50:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214054#M91771</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-06-11T07:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214055#M91772</link>
      <description>You want to "rename"&lt;BR /&gt;&lt;BR /&gt;/var/tmp/xyz.pdf to ./Result/abc.pdf&lt;BR /&gt;&lt;BR /&gt;You need to copy the source to the target and delete the source - well known as move.&lt;BR /&gt;If you give the target file another name while creating, you have what you want.</description>
      <pubDate>Wed, 11 Jun 2008 10:42:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214055#M91772</guid>
      <dc:creator>Torsten.</dc:creator>
      <dc:date>2008-06-11T10:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214056#M91773</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Now you see the immediate value of interrogating the 'errno' on failure of a system call, as I first suggested.  Interestingly, too, your failure (EXDEV) was the one I suspected as I noted :-)&lt;BR /&gt;&lt;BR /&gt;Using the shell 'mv' command does a *copy* in lieu of a 'rename' whenever a file resides in different filesystems.  You could take this middle-ground in your code:&lt;BR /&gt;&lt;BR /&gt;If the source and destination names aren't at the same root directory, you could assume that different filesystem may be involved and call 'system()' with 'mv', otherwise you could perform the 'rename()' directly.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 11 Jun 2008 10:56:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214056#M91773</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-11T10:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214057#M91774</link>
      <description>&lt;BR /&gt;Thanks all&lt;BR /&gt;system move command is working fine in unix..Its is not working in windows.But i need a way that renames the file both in unix and windows.</description>
      <pubDate>Wed, 11 Jun 2008 12:00:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214057#M91774</guid>
      <dc:creator>Soumya Krishnan</dc:creator>
      <dc:date>2008-06-11T12:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214058#M91775</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; But i need a way that renames the file both in unix and windows&lt;BR /&gt;&lt;BR /&gt;use Perl;&lt;BR /&gt;&lt;BR /&gt;Write a simple Perl script using the File::Copy module.  This implements things in a platform independent fashion.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 11 Jun 2008 12:07:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214058#M91775</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-11T12:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214059#M91776</link>
      <description>If this is C code, you can do your own move.&lt;BR /&gt;Open the file, read it and write the contents to a new file. Close both and delete the source. Don't forget some error checking/exception handling.</description>
      <pubDate>Wed, 11 Jun 2008 12:09:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214059#M91776</guid>
      <dc:creator>Torsten.</dc:creator>
      <dc:date>2008-06-11T12:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214060#M91777</link>
      <description>&amp;gt; But i need a way that renames the file both&lt;BR /&gt;&amp;gt; in unix and windows.&lt;BR /&gt;&lt;BR /&gt;I thought that I explained how to do it, as&lt;BR /&gt;have others.  I even explained how to avoid&lt;BR /&gt;the problem by writing your temporary file to&lt;BR /&gt;the right place, instead of to "/var/tmp".&lt;BR /&gt;Do you need someone to write the code for&lt;BR /&gt;you, or what?  What's not clear yet?</description>
      <pubDate>Wed, 11 Jun 2008 15:19:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214060#M91777</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-06-11T15:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214061#M91778</link>
      <description>Hii...&lt;BR /&gt;&lt;BR /&gt;Thanks alot........&lt;BR /&gt;It is working fine now.I have used Preprocessor directives for the compatiblity problem .&lt;BR /&gt;#ifdef UNIX&lt;BR /&gt;&lt;BR /&gt;system("mv /var/tmp/xyz.pdf ./Result/abc.pdf");&lt;BR /&gt;&lt;BR /&gt;#else &lt;BR /&gt; if(rename(tmpfn[0], filename))&lt;BR /&gt;  {&lt;BR /&gt;  map_msg_err("Can't rename temp-PDF file '%s' to '%s'\n", tmpfn[0], filename);&lt;BR /&gt;   mexit(EXIT_PDFRENAME);&lt;BR /&gt;  }&lt;BR /&gt;#endif&lt;BR /&gt;&lt;BR /&gt;Once again thanking u all for ur valubale suggestions...:-)</description>
      <pubDate>Wed, 11 Jun 2008 15:21:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214061#M91778</guid>
      <dc:creator>Soumya Krishnan</dc:creator>
      <dc:date>2008-06-11T15:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214062#M91779</link>
      <description>Even if this works under some circumstances, I really doubt if "rename" will always "move" your file ... but it's your code ...</description>
      <pubDate>Wed, 11 Jun 2008 15:28:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214062#M91779</guid>
      <dc:creator>Torsten.</dc:creator>
      <dc:date>2008-06-11T15:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214063#M91780</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;As a new Forum member, welcome!  If you are happy with the suggestions you have received, please read:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums11.itrc.hp.com/service/forums/helptips.do?#28" target="_blank"&gt;http://forums11.itrc.hp.com/service/forums/helptips.do?#28&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 11 Jun 2008 15:31:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214063#M91780</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-11T15:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214064#M91781</link>
      <description>&amp;gt; [...] ... but it's your code ...&lt;BR /&gt;&lt;BR /&gt;Yeah.  Sometimes it'd be nice to know more&lt;BR /&gt;about the people who post these questions, so&lt;BR /&gt;you'd know what not to buy.</description>
      <pubDate>Wed, 11 Jun 2008 15:35:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214064#M91781</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-06-11T15:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: Rename a file in C++ on Unix platform</title>
      <link>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214065#M91782</link>
      <description>LOL&lt;BR /&gt;&lt;BR /&gt;Steven, we have the same point of view.</description>
      <pubDate>Wed, 11 Jun 2008 15:38:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/rename-a-file-in-c-on-unix-platform/m-p/4214065#M91782</guid>
      <dc:creator>Torsten.</dc:creator>
      <dc:date>2008-06-11T15:38:46Z</dc:date>
    </item>
  </channel>
</rss>

