Solved

Using CFile::Rename

Posted on 2002-04-30
2
848 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

863 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

21 Experts available now in Live!

Get 1:1 Help Now