Solved

Using CFile::Rename

Posted on 2002-04-30
2
841 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
2 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 50 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video discusses moving either the default database or any database to a new volume.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now