| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | How to delete a read-only file? |
Hi Erwin,
you asked:
EH> How can I reset the READONLY-attribute of a file in order to be able to
EH> overwrite or delete it? It is probable plain simple but I can't figure it
EH> out. This is what I tried:
wow! a lot of coding. Try this:
=================================== snip ===================================
/* Warning: this code removes files, irrespectively of the read-only flag */
#include
#include
#include
#include
main(argc, argv)
int argc;
char *argv[];
{
int res=2; /* Check for write permission */
if (argc<2) /* Is an argument specified? */
return 1;
if (access(argv[1], res) != 0) /* Check for write access */
chmod(argv[1], S_IWRITE); /* Force write access */
unlink(argv[1]); /* Remove the file */
return 0;
}
================================ end snip ====================================
access, chmod and unlink are not part of ANSI C, however they are commonly
found in OS/2, DOS, (some tastes of) Unix and Windows.
Groeten,
Henk
--- GoldED 2.50+
* Origin: Henks Toolbox (00-06h), Mail only (2:286/415)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: 286/415 4 700 280/801 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™.