Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7577829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:17:15+00:00 2026-05-30T17:17:15+00:00

I have the below code and for some reason, rename(..) function is failing. I

  • 0

I have the below code and for some reason, rename(..) function is failing. I have tried supplying full paths, as well as changing working directory and then supplying just filenames. Below is the latter which fails and errno is 13. All files are in my Projects folder of this win32 console project. I don’t understand why it is so difficult to simply change a filename, regardless of what the current working dir is.

//fname_string* points to beginning of actual filename
//filename contains entire output file path
//file_ext* points to .csv portion
//fname will get old filename
fname_string = strrchr( filename, '\\' );
if( fname_string == NULL )
{
    fname_string = filename;    //no dir supplied, so set it to filename
}
else
{
    strncpy( fname, filename, fname_string - filename );
    fname[fname_string-filename] = '\0';
    chdir(fname);
    fname_string++; //now points to filename
    read_success = errno; //this succeeds supposedly
}

strcpy( fname, fname_string );  //save old file path
sprintf( file_ext, "_%d.csv", append_esn ); //append_esn = 1234
read_success = rename( fname, fname_string );
read_success = errno;  //giving me 13

EDIT:
I’m dumb and I was closing the ‘input’ file, and not the ‘output’ file. So FYI, file better be closed! The reason why I thought it was closed is because I flush the output file and sometimes it didn’t have a zero size file.

So rename can take a full path or just the filenames if its in the working directory…There goes two hours of nonsense….
So the above would work, or just doing the below assuming same pointers mentioned above:

strcpy( fname, filename );  //save old file path
sprintf( file_ext, "_%d.csv", append_esn );
read_success = rename( fname, filename );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:17:16+00:00Added an answer on May 30, 2026 at 5:17 pm

    My last comment above answers this question/issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have the code below that for some reason is not working: I
For some reason the code I have included below does not interpolate the variables
I have the below code but for some reason I cannot get the correct
For some reason the code below isn't centering my Unordered List (I have the
I have the below code to open a CSV file, but for some reason
I have some problem with my cfml website. I have used the below code
I have some really funky code. As you can see from the code below
For some reason the code below is returning the results, put not in the
The below code works, but for some reason the $('#chart').fadeTo callback seems to create
MVC3 VB.NET application. I have the below section of code in a function. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.