Check if a file attribute is readonly

147 views
Skip to first unread message

ujayadev_at_gmail.com

unread,
Aug 22, 2012, 5:03:39 AM8/22/12
to harbou...@googlegroups.com
Hi All,

How to check if a file has an attribute of Readonly while opening. (it can be text, dbf, anything)

Case:

Some users, while creating their files mark it as readonly by changing the file properties directly from Windows Os..  Write commands later fail as the user tries to write to the same file without realizing that it has been marked readonly.

Kindly advice.

Warm regards,

Jayadev

Bernard Mouille

unread,
Aug 22, 2012, 7:59:53 AM8/22/12
to Harbour Users
Hello Jayadev,

Look home Giovani Di Maria : ADIR() function :
http://www.elektrosoft.it/tutorials/Harbour-Reference-Guide/harbour-reference-guide.htm#ADir

Bernard

ujayadev_at_gmail.com

unread,
Aug 22, 2012, 8:26:56 AM8/22/12
to harbou...@googlegroups.com
Dear Bernard,

Many thanks for your pointer.  What I was looking for is as to how to check the attribute of one file which needs to be opened. Maybe it requires some C function.  Pls see directory() C function for example.

I would like to request a function such as IsReadOnly(cFileName) if possible.

Warm regards,

Jayadev

Bernard Mouille

unread,
Aug 22, 2012, 10:13:23 AM8/22/12
to Harbour Users
Hello Jayadev,

Try my code delow my sinature :

Bernard

// begin code

* Test.prg - Programme de test.
* -----------------------------
*

/*


*/


/* File attributes flags (in fileio.ch) */

#define HB_FA_ALL 0x00000000

#define HB_FA_READONLY 0x00000001 /* R */
#define HB_FA_HIDDEN 0x00000002 /* H */
#define HB_FA_SYSTEM 0x00000004 /* S */
#define HB_FA_LABEL 0x00000008 /* V */
#define HB_FA_DIRECTORY 0x00000010 /* D | S_ISDIR() */
#define HB_FA_ARCHIVE 0x00000020 /* A | S_ISREG() */
#define HB_FA_DEVICE 0x00000040 /* I | S_ISBLK() */
#define HB_FA_NORMAL 0x00000080 /* */

#define HB_FA_TEMPORARY 0x00000100 /* T | S_ISFIFO()??? */
#define HB_FA_SPARSE 0x00000200 /* P | S_ISSOCK()??? */
#define HB_FA_REPARSE 0x00000400 /* L | S_ISLNK() */
#define HB_FA_COMPRESSED 0x00000800 /* C | S_ISCHR()??? */
#define HB_FA_OFFLINE 0x00001000 /* O */
#define HB_FA_NOTINDEXED 0x00002000 /* X */
#define HB_FA_ENCRYPTED 0x00004000 /* E */
#define HB_FA_VOLCOMP 0x00008000 /* M volume supports
compression. */

*
* --------------
PROCEDURE Main
* --------------
*
* TODO : variables MEMVAR.
* TODO : variables LOCAL.
*
LOCAL cFile := "Test.txt"
*
SET DATE FRENCH
*
* Mise en ANSI (Windows) langue française.
*
REQUEST HB_LANG_FR
REQUEST HB_CODEPAGE_FRWIN
HB_CDPSELECT('FRWIN')
HB_LANGSELECT('FR')
*
SETMODE( 43, 80 ) && Lignes et
colonnes d'affichage écran.
*
? IsReadOnly( cFile )
*
?
?
WAIT
*
RETURN
*
* --------------------------------------
FUNCTION IsReadOnly( cFile )
* --------------------------------------
*
LOCAL nAttrib
*
hb_FGetAttr( cFile, @nAttrib )
*
IF MOD( nAttrib, 2 ) == 1
RETURN .T.
ENDIF
*
RETURN .F.


// end code

On 22 août, 14:26, "ujayadev_at_gmail.com" <ujaya...@gmail.com> wrote:
> Dear Bernard,
>
> Many thanks for your pointer.  What I was looking for is as to how to check
> the attribute of one file which needs to be opened. Maybe it requires some
> C function.  Pls see directory() C function for example.
>
> I would like to request a function such as IsReadOnly(cFileName) if
> possible.
>
> Warm regards,
>
> Jayadev
>
>
>
> On Wednesday, August 22, 2012 5:29:53 PM UTC+5:30, Bernard Mouille wrote:
>
> > Hello Jayadev,
>
> > Look home Giovani Di Maria :  ADIR() function :
>
> >http://www.elektrosoft.it/tutorials/Harbour-Reference-Guide/harbour-r...

ujayadev_at_gmail.com

unread,
Aug 23, 2012, 2:06:19 AM8/23/12
to harbou...@googlegroups.com
Dear Bernard,

Many thanks for your reply.  I shall try and revert in case of difficulty.

Warm regards,

Jayadev.

Bernard Mouille

unread,
Aug 23, 2012, 5:14:36 AM8/23/12
to Harbour Users
Hello Jayadev,

You can look for hb_FGetAttr() here :
http://bernard.mouille.free.fr/0_Harbour/ZD00000013/000001.html

Good developpement,

BERNARD

On 23 août, 08:06, "ujayadev_at_gmail.com" <ujaya...@gmail.com> wrote:
> Dear Bernard,
>

Massimo Belgrano

unread,
Aug 23, 2012, 5:55:05 AM8/23/12
to harbou...@googlegroups.com
very intresting your sample at  http://bernard.mouille.free.fr/0_Harbour/

The idea that with a collection of sample prg
will explained many function


2012/8/23 Bernard Mouille <bernard...@wanadoo.fr>
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users



--
Massimo Belgrano


Jayadev Urath

unread,
Aug 23, 2012, 7:01:33 AM8/23/12
to harbou...@googlegroups.com
Dear Bernard,

Many thanks for your excellent example.  Though I don't speak French, still merci :-)

Warm regards,

Jayadev


Bernard Mouille

unread,
Aug 23, 2012, 7:01:43 AM8/23/12
to Harbour Users
Thank's Massimo,

I do this site because my memory (in my brain) is not very good.
It is also for the people who speak french and not english.

Bernard

On 23 août, 11:55, Massimo Belgrano <mbelgr...@deltain.it> wrote:
> very intresting your sample at  http://bernard.mouille.free.fr/0_Harbour/
> imo are best addiction forhttp://www.elektrosoft.it/tutorials/Harbour-Reference-Guide/harbour-c...
>
> The idea that with a collection of sample prg
> will explained many function
>
> 2012/8/23 Bernard Mouille <bernard.moui...@wanadoo.fr>

SD

unread,
Aug 24, 2012, 11:23:27 AM8/24/12
to harbou...@googlegroups.com
On Wednesday, August 22, 2012 7:43:23 PM UTC+5:30, Bernard Mouille wrote:
Hello Jayadev,
Try my code delow my sinature :
Bernard
// begin code
* Test.prg - Programme de test.
* -----------------------------

The code looks like a great example as per the requirement of Jayadev. Jayadev let us know the output of your test drive of this code.
Thank you so much Bernard Mouille for this example. Your site looks like a good resourceful site for Harbour users. Though I don't understand French...

Regards,
Swapan
Message has been deleted

ujayadev_at_gmail.com

unread,
Aug 25, 2012, 7:49:33 AM8/25/12
to harbou...@googlegroups.com
Dear Bernard,

The code posted at the link below fails at call to function WIN_GETOPENFILENAME(), where I can find information about this function.

Warm regards,

Jayadev
Message has been deleted

Klas Engwall

unread,
Aug 25, 2012, 9:03:13 AM8/25/12
to harbou...@googlegroups.com
Hi Jayadev,

> The code posted at the link below fails at call to function
> WIN_GETOPENFILENAME(), where I can find information about this function.

All functions with a "WIN_" prefix exist in the hbwin lib

Regards,
Klas

Bernard Mouille

unread,
Aug 25, 2012, 9:19:22 AM8/25/12
to Harbour Users
Hello Jayadev,

I use WIN_GETOPENFILENAME() in my basic sample to select a file for
test.

You can fins some things here :
- HB.3.0.0\Changelog.txt
- http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839(v=vs.85).aspx
- http://bernard.mouille.free.fr/0_Harbour/ZD00000005/000001.html ( in
french ).

You must compile with hbwin.lib and it works.

I do not know if it works in Linux, I work only in Windows.

Have a good afternoon,

Bernard

On 25 août, 13:49, "ujayadev_at_gmail.com" <ujaya...@gmail.com> wrote:
> Dear Bernard,
>

Jayadev Urath

unread,
Aug 25, 2012, 9:28:02 AM8/25/12
to harbou...@googlegroups.com
Dear Klas/Bernard,

Many thanks for the info.

Have a nice weekend.

Warm regards,

Jayadev

--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.

Reply all
Reply to author
Forward
0 new messages