?
Solved

Using CFile::Rename

Posted on 2002-04-30
2
Medium Priority
?
871 Views
Last Modified: 2013-11-20
I am using code like this:

CFile fl;
fl.Open("C:\\SomeFile.txt", CFile::modeWrite);
fl.Rename(fl.GetFileName(), "SomeFile2.txt");
fl.Close();

This produces an error message: A sharing violation occurred when accessing an unnamed file.

What the heck is going on?

Thanks a lot!
-Dan
0
Comment
Question by:SuperMario
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 200 total points
ID: 6981718
CFile::Rename cannot be used to rename a currently opened and locked file.

Further, you need not open the file to use CFile::Rename since this function is static.

Just do:

CFile fi;
fi.Open(whatever....);
fi.Close();
CFile::Rename("C:\\SomeFile.txt", "SomeFile2.txt");
0
 
LVL 3

Author Comment

by:SuperMario
ID: 6981732
Whee! Thanks so much!
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question