Solved

Using CFile::Rename

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
string initialization in java 11 115
countEvens challenge 2 112
Problem to App source 6 73
I could not set window to top 4 21
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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 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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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