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

Deleting Hidden System Files Through Fox 2

Status
Not open for further replies.

dazman72

Programmer
Feb 19, 2003
3
0
0
GB
I am trying to delete a system hidden file through my licencing program using the command DELETE FILE. However, it will not delete because it is hidden. I have tried changing the attribute with !ATTRIB but is not working correctly and is too messy. I have tried doing FCREATE(filename,0) to make file Read/Write so I can then delete but the file is still staying as a Hidden System file.

Any ideas please??
 
Here's a routine that may do it for you. Thanks to news2news.com. I'll let you modify it to suit your needs:
Code:
*... setfileattrib.prg ...
LPARAMETERS  lpFileName 

#DEFINE FILE_ATTRIBUTE_READONLY       1   
#DEFINE FILE_ATTRIBUTE_HIDDEN         2   
#DEFINE FILE_ATTRIBUTE_SYSTEM         4   
#DEFINE FILE_ATTRIBUTE_DIRECTORY     16   
#DEFINE FILE_ATTRIBUTE_ARCHIVE       32   
#DEFINE FILE_ATTRIBUTE_NORMAL       128   
#DEFINE FILE_ATTRIBUTE_TEMPORARY    512   
#DEFINE FILE_ATTRIBUTE_COMPRESSED  2048   
       
DECLARE SHORT SetFileAttributes IN kernel32; 
    STRING lpFileName, INTEGER dwFileAttributes 

DECLARE INTEGER GetFileAttributes IN kernel32 STRING lpFileName  

* read current attributes for this file 
dwFileAttributes = GetFileAttributes (lpFileName) 

IF dwFileAttributes = -1 
* the file does not exist 
    RETURN 
ENDIF 

IF dwFileAttributes > 0 
    * read-only attribute to be set 
    dwFileAttributes = BitOr(dwFileAttributes, FILE_ATTRIBUTE_READONLY) 
         
    * archive attribute to be removed 
    IF BitAnd(dwFileAttributes, FILE_ATTRIBUTE_ARCHIVE) = FILE_ATTRIBUTE_ARCHIVE 
        dwFileAttributes = dwFileAttributes - FILE_ATTRIBUTE_ARCHIVE 
    ENDIF 

    * setting selected attributes 
    = SetFileAttributes (lpFileName, dwFileAttributes) 
ENDIF 
RETURN
Dave S.
[cheers]
 
You'll have to reset the attribute before FoxPro can delete it. If !ATTRIB is "too messy", you have at least two other choices - WSH or the WinAPI.
Code:
** COMMON **
lcfile = "filetodelete.txt"

#define FILE_ATTRIBUTE_READONLY             0x00000001  
#define FILE_ATTRIBUTE_HIDDEN               0x00000002  
#define FILE_ATTRIBUTE_SYSTEM               0x00000004  
#define FILE_ATTRIBUTE_ARCHIVE              0x00000020  
#define FILE_ATTRIBUTE_NORMAL               0x00000080  
#define FILE_ATTRIBUTE_TEMPORARY            0x00000100  
#define FILE_ATTRIBUTE_OFFLINE              0x00001000  
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000

* Windows Script Code (WSH) *
oFSO = CREATEOBJECT('Scripting.FileSystemObject')
* lcfile is a valid file (it exists).
oFile = oFSO.GetFile(lcfile)
oFile.Attributes = BITAND(oFile.Attributes, BITNOT(FILE_ATTRIBUTE_HIDDEN))
oFile = .null.

* OR 

* WinAPI Code
declare short SetFileAttributes in Win32API ;
  string @ lpFileName,;
  integer dwFileAttributes
declare integer GetFileAttributes in Win32API ;
  string @ lpFileName

lnCurAttributes = GetFileAttributes(lcFile)
= SetFileAttributes(lcFile, ;
   BITAND(lnCurAttributes, BITNOT(FILE_ATTRIBUTE_HIDDEN)))
Rick
 
Hi there

I'm about to send a new application out on CD and as dazman72 said using !ATTRIB to reset the readonly attributes would have made the installation process look a bit wild.

The WinAPI code is still beyond me but thanks to you and your sources (and of course Tek-Tips) I'm beginning to see the light!

Sent you a star each for your replies...

Kaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top