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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Attributes

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
0
0
SE
Hello, 801119 here..!<br><br>With my Text program that I am writing for the moment I will give the ability to delete the current file. For the moment I am using.... <br>DeleteFile(FFileName); // FFileName is the Name to be deleted.<br>And there are one more way(that I know) to delete a file that I encountered when<br>I searched the help documents.<br>My short way works aslong as the file is not set to ReadOnly<br>When I read the help files i found this way to change file attributes:<br>extern PACKAGE int __fastcall FileSetAttr(const System::AnsiString FileName, int Attr);<br>First I do not know how to use this on, I tried to call it from an other function<br>FileSetAttr(FFileName, faReadOnly); // is faReadOnly the correct attribute to use in this example<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to remove ReadOnly from a file??<br>Did not work so well...... How do I make it work??<br>Or is there a better way to change file attributes??
 
80119,<br><br>&nbsp;&nbsp;&nbsp;&nbsp;You may want to try <i>chmod</i>. This will work with DOS, Unix, Win 16, Win 32, amd Ansi C++ so it should be well documented. <i>chmod</i> can be found in <i>io.h</i>. The structure is:<br><br>int chmod(const char *path, int amode);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Path is the full path to the file you want to change. Amode will be either S_IWRITE, S_IREAD, or S_IWRITE ¦ S_IREAD where S_IWRITE gives the file write permission and S_IREAD give the file read permission.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;<i>chmode</i> returns either 0 for no error or -1 for an error. An error will also set the global variable <i>errno</i>. All this should be in your help files. <br><br>&nbsp;&nbsp;&nbsp;&nbsp;If you need more help on this function or you need file attribute function, post back to this thread and I or someone can help further.<br><br> <p>James P. Cottingham<br><a href=mailto:main@ivcusa.com>main@ivcusa.com</a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.
 
Thanks 2ffat!<br><br>#include &lt;io.h&gt;<br>String path=&quot;c:\\command.com&quot;;<br><br>void __fastcall TForm1::Buton1Click(TObject *Sender)<br>{<br>int chmod(const char *path, int S_IWRITE ¦ S_IREAD)<br>DeleteFile(path); //Should delete a file<br>if(FileExists(path))<br>&nbsp;{<br>&nbsp;&nbsp;Application-&gt;MessageBox(&quot;File still exists&quot;,&quot;Error&quot;, MB_OK); //just to see if the file still exists<br>&nbsp;}<br>}<br><br><br>Is this the right way to use it??? for sure i tried it..<br>did nothing to the file. <br>What am I doing wrong??<br>Thanks for any further help! 801119
 
You have declared the function only. Where are you calling the function? You need to call the function chmod and check for the value returned. I 've changed the program a bit , please check now.<br>Thanx<br>Siddhartha Singh<br><br>#include &lt;io.h&gt;<br>String path=&quot;c:\\command.com&quot;;<br><br>void __fastcall TForm1::Buton1Click(TObject *Sender)<br>{<br><br>if(!chmod(&nbsp;&nbsp;path, S_IWRITE ¦ S_IREAD)) {<br>&nbsp;&nbsp;Application-&gt;MessageBox(&quot;Status changed successfully &quot;,&quot;Error&quot;, MB_OK); <br>}<br>else<br>Application-&gt;MessageBox(&quot;Error in changing the mode &quot;,&quot;Error&quot;, MB_OK); <br><br>DeleteFile(path); //Should delete a file<br>if(FileExists(path))<br>&nbsp;{<br>&nbsp;&nbsp;Application-&gt;MessageBox(&quot;File still exists&quot;,&quot;Error&quot;, MB_OK); //just to see if the file still exists<br>&nbsp;}<br>}<br><br><br> <p>Siddhartha Singh<br><a href=mailto:siddhu_singh@hotmail.com>siddhu_singh@hotmail.com</a><br><a href=siddhu.freehosting.net> </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top