Main
   Home
   About
   DiscussionBoard
Files
   About
   Submit
   Search
Downloads
   Action
   QB64
Links
   Link to us
QB45.org
[ Back to QB45 | FAQ | Search a message | Reply to this message | Back to messages ]

Antony on 03/05/09 - 22:06:12

Well, would you please tell me how to change the attributes of any file on PC..
I usualy use the SHELL statement to call ATTRIB from DOS..

Todd on 03/06/09 - 11:49:04

Here's some code I found in the ABC:


'> Can anyone give me some code so that I can set the read/write
'> attribute on files. Preferably something so that I can just pass a

' This ought to get you going. Note that you cannot change a file's
'attributes to a directory or a volume label with this. The interrupt
'routine will not allow it. getfileattr% returns the file's attributes,
'or -1 if an error occured. setfileattr% set's a file's attributes and
'returns 0 for success or -1 if there was an error. You'll need to
'start QB with "/l" so it will load the interrupt quick-library.

'$INCLUDE: 'qb.bi'
DECLARE FUNCTION getfileattr% (filename$)
DECLARE FUNCTION setfileattr% (filename$, attribute%)

'bit
' 8 : shareable (Novell NetWare)
' 7 : unused
' 6 : unused
' 5 : archive
' 4 : directory
' 3 : volume label
' 2 : SYSTEM
' 1 : hidden
' 0 : read-only
'
'get file attributes
'
filename$ = "test.fil" 'Change this to an existing filename!
t% = getfileattr%(filename$)
IF t% = -1 THEN PRINT "Error" ELSE PRINT "Attribute="; t%
'
'set file attributes
'
filename$ = "test.fil" 'Change this to an existing filename!
attribute% = 32 'set archive bit
t% = setfileattr%(filename$, attribute%)
IF t% THEN PRINT "Error"

FUNCTION getfileattr% (filename$)
DIM regsx AS regtypex
regsx.ax = &H4300
testname$ = filename$ + CHR$(0)
regsx.ds = VARSEG(testname$)
regsx.dx = SADD(testname$)
interruptx &H21, regsx, regsx
IF regsx.flags AND 1 THEN
getfileattr% = -1
ELSE
getfileattr% = regsx.cx
END IF
END FUNCTION

FUNCTION setfileattr% (filename$, attribute%)
DIM regsx AS regtypex
testname$ = filename$ + CHR$(0)
regsx.ax = &H4301
regsx.cx = attribute%
regsx.ds = VARSEG(testname$)
regsx.dx = SADD(testname$)
interruptx &H21, regsx, regsx
IF regsx.flags AND 1 THEN
setfileattr% = -1
ELSE
setfileattr% = 0
END IF
END FUNCTION

'> ALSO....

'> Does anyone have any code for SETTING the DOS volume label of a floppy?

' The only way I've successfully done it is with int 21 function 6c
'(extended open/create), which only works with DOS 4.0+. There's got to
'be a better way and maybe someone else here knows it.


Reply to this message
Name:
Message:
Please enter this number:
No HTML allowed. You may use BB-code in your posting.
Members
Login
Register
QB45 Members
Member List