Solved

Using CFile::Rename

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

778 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