Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Read-Only Files

Status
Not open for further replies.

TheCrappyProgrammer

Programmer
Sep 17, 2001
41
US
How do I delete Read-Only files and other files that are in use by another program?
 
you can use the "GetFileAttributes" function to get the files attributes and use "DeleteFile" to delete them.

for deleting a specific file,you would have something like:

if( GetFileAttributes( lpfilename ) == FILE_ATTRIBUTE_READONLY )
DeleteFile( lpfilename );
 
1. Readonly:
DWORD attr = GetFileAttributes(PathName);
attr &= ~FILE_ATTRIBUTE_READONLY;
SetFileAttributes(PathName, attr );
DeleteFile( PathName );
2. With used files, it is not so easy. You can try to use UnmapViewOfFile() and UnlockFile(), but it works not allways. There are three ways: terminate the program which uses the file, delete it by next reboot or play with assembler codes - look for old samples with assembler.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top