Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Command in FoxPro Similar to attrib in dos ?
Message
 
 
To
24/10/2000 15:56:06
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00433751
Message ID:
00433757
Views:
15
>Does FoxPro have a command that will allow changing of the attributes on a file ? Or can I delete a read only file in FoxPro. The files I need to delete are BMP picture files.

The native VFP ERASE and DELETE FILE command will not delete a read-only file. You will need to change the attribute first. Here is some code that will do it using Filer.DLL (not distributable):
#define FILE_ATTRIBUTE_READONLY             0x00000001  

LPARAMETERS cFileSpec, cNewAttribute

IF PCOUNT() < 2 ;
   OR VARTYPE( cFileSpec ) # "C" OR VARTYPE( cNewAttribute ) # "C" ;
   OR EMPTY( cFileSpec ) OR EMPTY( cNewAttribute )
   MESSAGEBOX( "Parameters: cFileSpec and cNewAttribute must be passed in."  )
   RETURN .F.
ENDIF

IF NOT FILE( cFileSpec )
   MESSAGEBOX( "File: " + cFileSpec + ", not present." )
   RETURN .F.
ENDIF

IF NOT INLIST( cNewAttribute, "+R", "-R" )
   MESSAGEBOX( "cNewAttribute must be one of +R or -R" )
   RETURN .F.
ENDIF

oFiler = CREATEOBJECT( "Filer.FileUtil" )

WITH oFiler
   .SearchPath = JUSTPATH( cFileSpec )
   .FileExpression = JUSTFNAME( cFileSpec )
   .Find( 0 )	&& Search, discarding last collection.
   iCurrentAttribute = .Files.Item(1).Attr
   IF cNewAttribute = "-"
      *- Remove Read Only.
      iNewAtribute = BITAND( iCurrentAttribute, BITNOT( FILE_ATTRIBUTE_READONLY ))
   ELSE
      *- Add Read Only.
      iNewAtribute = BITOR( iCurrentAttribute, FILE_ATTRIBUTE_READONLY )
   ENDIF
   .Files.Item(1).Attr = iNewAtribute
ENDWITH
RETURN .T.
censored.
Previous
Reply
Map
View

Click here to load this message in the networking platform