title: permission denied for rename function in C on windows
body: <p>I have an application developed in C. This application is supported across multiple platforms. There is one functionality where we are transferring files via file transfer protocol to different machine or to any other directory on local machine. I want to include a functionality where I can transfer the file with some temporary name and once the transfer is complete, I want to rename the file with the correct name (the actual file name).</p>
  
  <p>I tried using simple rename() function. It works fine in Unix and Linux machines. But it does not work on Windows. It is giving me an error code of 13(Permission denied error).</p>
  
  <p>First thing, I checked in msdn to know the functionality of rename if I have to grant some permissions to the file etc. </p>
  
  <ol>
  <li>I granted full permissions to the file (lets say it is 777).</li>
  <li>I read in few other posts that I should close the file descriptor before renaming the file. I did that too. It still gives the same error. </li>
  <li>Few other posts mentioned about the owner of the file and that of the application. The application will run as a SYSTEM user. (But this should not affect the behavior, because I tried the same rename function in my application as follows:</li>
  </ol>
  
  <p>This works fine from my application:</p>
  
  <pre><code>rename("C:/abc/aaa.txt","C:/abc/zzz.txt");
  </code></pre>
  
  <p>but</p>
  
  <pre><code>rename(My_path,"C:/abc/zzz.txt");
  </code></pre>
  
  <p>doesn't work, where <code>My_path</code> when printed displays <code>C:/abc/test.txt</code>.</p>
  
  <p>How can I rename a file? I need it to work on multiple platforms. 
  Are there any other things I should be trying to make it work.?</p>