| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | How to delete a read-only file? |
Hi,
How can I reset the READONLY-attribute of a file in order to be able to
overwrite or delete it? It is probable plain simple but I can't figure it
out.
This is what I tried:
FileFlags = FILE_READONLY; /* doesn't really matter */
FileOpenAction = OPEN_ACTION_OPEN_IF_EXISTS;
FileAccess = OPEN_ACCESS_READONLY| OPEN_SHARE_DENYNONE;
/* Open the file in readonly mode to see if it exists. */
/* Can't use DosFindFirst() here cause I need a FileHandle in */
/* DosQueryFileInfo */
/* OPEN_ACCESS_READONLY and OPEN_SHARE_DENYNONE must be set */
rc = DosOpen (Fname, /* File path name */
&hfFileHandle, /* File handle */
&ulAction, /* Action taken */
(long) DirPointer->FileSize, /* File primary allocation */
FileFlags, /* File attribute */
FileOpenAction,
FileAccess, /* Open mode of the file */
0L); /* No extended attribute */
if (rc == NO_ERROR) /* NO_ERROR if file exists */
{
if (Verbose)
printf (" File exists.\n");
/* Read file attributes */
rc = DosQueryFileInfo (hfFileHandle, FIL_STANDARD,
&fsts3FileInfo, ulBufferSize);
if (rc != NO_ERROR)
{
printf (" DosQueryFileInfo error: return code = %u line =
%d\n", (unsigned int) rc, __LINE__);
return rc;
}
/* Reset readonly, hidden and system flags */
fsts3FileInfo.attrFile = FILE_NORMAL;
/* This one trows (of course) an ERROR_ACCESS_DENIED at me */
rc = DosSetFileInfo (hfFileHandle, FIL_STANDARD,
&fsts3FileInfo, ulBufferSize);
if (rc != NO_ERROR)
{
printf (" DosSetFileInfo error: return code = %u line =
%d\n", (unsigned int) rc, __LINE__);
return 1;
}
/* close the file and re-open it so it can be overwritten */
rc = DosClose (hfFileHandle); /* Close the file */
if (rc != NO_ERROR)
{
printf (" DosClose error: return code = %u line = %d\n",
(unsigned int) rc, __LINE__);
return 1;
}
What do I miss here?
Bye, Erwin Hogeweg
fidonet : 2:500/120.6046
OS2NET : 81:431/520.6046
e-mail : e.hogeweg{at}dosgg.nl
---
* Origin: Highway Express/2 (2:500/120.6046)SEEN-BY: 50/99 54/99 270/101 620/243 625/155 711/401 413 430 934 712/311 407 SEEN-BY: 712/505 506 517 623 624 704 713/317 800/1 @PATH: 500/120 7 9 3 396/1 270/101 712/624 711/934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.