?
Solved

How do I change a 'read only' file in Foxpro ver 8

Posted on 2010-01-12
9
Medium Priority
?
1,919 Views
Last Modified: 2012-05-08
I wish to modify structure in a read only file in Foxpro. How do I change file status in order for me to modify field order. I do have source codes. I am not a programmer but can do simple Foxpro manouvres so please explain in laymans terms if indeed it can be done
Thank you
Ian
0
Comment
Question by:racepro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 1500 total points
ID: 26291869
To change file attributes you may use slyghtly updated procedures published at http://www.tek-tips.com/faqs.cfm?fid=3327 (see code snippet).

You should also look at the file type in your code. If it is read-only cursor then you cannot change its attributes this way because it is a temporary file which will be deleted when you close it. If the file is created in your app then you should create it with appropriate structure at the beginning instead of changing R/O state and updating the structure.

If it is just one time change of a permanent file then you could do it via OS file properties dialog and the change the structuire in VFP Command window:

USE File EXCLUSIVE
MODIFY STRUCTURE

Doing that programmatically you may use ALTER TABLE command.
PROCEDURE SetFileAttr( pcFile, pcAttr )
* Author: William GC Steinford 2003
* Takes a file and a list of attributes to change on the file, and does the change
*
* pcFile  : either just the file name or the full path to the file.
*           Either way, the full path will be resolved using FULLPATH()
* pcAttrs : a list of attributes to change on the file
*           if the attribute character is Uppercase it will be turned on,
*             Lowercase, it will be turned off, 
*             Not listed, it will be left alone.
*           a,A - Archive
*           s,S - System
*           h,H - Hidden
*           r,R - Read Only
*           i,I - Not Content-Indexed
*           t,T - Temporary Storage (try to keep in memory)
*           N   - Normal (clear all other attributes)

*!*    BOOL SetFileAttributes(
*!*      LPCTSTR lpFileName,      // file name
*!*      DWORD dwFileAttributes   // attributes
*!*    )
*!*    DWORD GetFileAttributes(
*!*      LPCTSTR lpFileName   // name of file or directory
*!*    )

#define FILE_ATTRIBUTE_READONLY             0x00000001
#define FILE_ATTRIBUTE_HIDDEN               0x00000002
#define FILE_ATTRIBUTE_SYSTEM               0x00000004
#define FILE_ATTRIBUTE_DIRECTORY            0x00000010
#define FILE_ATTRIBUTE_ARCHIVE              0x00000020
#define FILE_ATTRIBUTE_ENCRYPTED            0x00000040
#define FILE_ATTRIBUTE_NORMAL               0x00000080
#define FILE_ATTRIBUTE_TEMPORARY            0x00000100
#define FILE_ATTRIBUTE_SPARSE_FILE          0x00000200
#define FILE_ATTRIBUTE_REPARSE_POINT        0x00000400
#define FILE_ATTRIBUTE_COMPRESSED           0x00000800
#define FILE_ATTRIBUTE_OFFLINE              0x00001000
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000

DECLARE INTEGER GetFileAttributes IN kernel32; 
    STRING lpFileName
DECLARE SHORT SetFileAttributes IN kernel32; 
    STRING lpFileName,; 
    INTEGER dwFileAttributes  

LOCAL lcFile, lnAttr, lcAttr, laDir[1]
lcFile = FULLPATH(pcFile)
* File() doesn't see Hidden or system files: if NOT FILE(pcFile)
IF adir(laDir,lcFile,'DHS')=0
  RETURN .F.
endif
lcAttr = upper(pcAttr)

if 'N' $ pcAttr
  * "NORMAL" must be used alone.
  lnRes = SetFileAttributes(lcFile,FILE_ATTRIBUTE_NORMAL)
  RETURN (lnRes<>0)
endif

lnAttr = GetFileAttributes( lcFile )
* These attributes Can't be set using SetFileAttributes:
lnAttr = BitAnd( lnAttr, BitNot( FILE_ATTRIBUTE_COMPRESSED ;
     + FILE_ATTRIBUTE_DIRECTORY + FILE_ATTRIBUTE_ENCRYPTED ;
     + FILE_ATTRIBUTE_REPARSE_POINT ;
     + FILE_ATTRIBUTE_SPARSE_FILE ) )
if 'A' $ lcAttr
  if 'A' $ pcAttr
    lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_ARCHIVE )
  else
    lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_ARCHIVE) )
  endif
endif
if 'R' $ lcAttr
  if 'R' $ pcAttr
    lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_READONLY )
  else
    lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_READONLY) )
  endif
endif
if 'H' $ lcAttr
  if 'H' $ pcAttr
    lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_HIDDEN )
  else
    lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_HIDDEN) )
  endif
endif
if 'S' $ lcAttr
  if 'S' $ pcAttr
    lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_SYSTEM )
  else
    lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_SYSTEM) )
  endif
endif
if 'I' $ lcAttr
  if 'I' $ pcAttr
    lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED )
  else
    lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) )
  endif
endif
if 'T' $ lcAttr
  if 'S' $ pcAttr
    lnAttr = BitOr( lnAttr, FILE_ATTRIBUTE_TEMPORARY )
  else
    lnAttr = BitAnd( lnAttr, BitNot(FILE_ATTRIBUTE_TEMPORARY) )
  endif
endif
if 'N' $ lcAttr
  lnAttr = iif('N'$pcAttr, FILE_ATTRIBUTE_NORMAL, lnAttr )
endif

lnRes = SetFileAttributes(lcFile,lnAttr)
RETURN (lnRes<>0)

FUNCTION GetFileAttr( tcFName )
*GetFileAttrib( cFName ) Return the File Attributes (RSHA)
*!*    DWORD GetFileAttributes(
*!*      LPCTSTR lpFileName   // name of file or directory
*!*    )
  DECLARE LONG GetFileAttributes IN Win32Api AS util_GetFileAttributes ;
    STRING LPCTSTR_lpFileName 
  LOCAL lnAttr, lcAttr
  lnAttr = util_GetFileAttributes( tcFName )
  CLEAR DLLS util_GetFileAttributes
  if lnAttr=0xFFFF
    RETURN 'error'
  ENDIF
  lcAttr = iif( BITAND(lnAttr,FILE_ATTRIBUTE_READONLY )>0, 'R', '' ) ;
         + iif( BITAND(lnAttr,FILE_ATTRIBUTE_HIDDEN   )>0, 'H', '' ) ;
         + iif( BITAND(lnAttr,FILE_ATTRIBUTE_SYSTEM   )>0, 'S', '' ) ;
         + iif( BITAND(lnAttr,FILE_ATTRIBUTE_ARCHIVE  )>0, 'A', '' ) ;
         + iif( BITAND(lnAttr,FILE_ATTRIBUTE_DIRECTORY)>0, 'D', '' )
  RETURN lcAttr

Open in new window

0
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 
LVL 42

Expert Comment

by:pcelba
ID: 26292026
Also:
http://www.news2news.com/vfp/?example=103&function=-1&xpg=13

and one from Microsoft:
http://support.microsoft.com/kb/184525

or Foxite...
http://www.foxite.com/archives/vfp-6-and-attributes-file-0000037650.htm

Simply use Google  :-)

I would say more important is the fact above routines do not help if it is read-only cursor...
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 26292049
I use Ecosia and got the first 3 results :-)

Google is the best however Ecosia saves the Earth.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 26292108
Hmm, it redirected me to www.google.cz
 
0
 

Author Closing Comment

by:racepro
ID: 31676017
The field order can be modified when opened in Windows Explorer but when I 'do' prg in Foxpro that brings up the file it goes back to the default.
As mentioned my knowledge extends to a few commands. Any changes made outside of file sructure is way beyond my capacity. But thanks for our help.
It seems like a job for a programmer
Ian
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 26292339
0
 
LVL 42

Expert Comment

by:pcelba
ID: 26292554
Yes,  ecosia.com but it redirected me directly to http://ecosia.org/ and results were comming from google.cz ... probably more ecological than direct request to google :-))

Question and notes to racepro:
You did not mention you are opening the DBF file in Windows Explorer and column order is always reset to the default state... It seems you don't need to change the file structure but the way how it is displayed. We even don't know what program displays the data...

If it is Visual FoxPro then the column order and much more is stored in resource file for future use and it should remain unchanged when you open the same DBF file next time. Resource file must be enabled, of course. This may be done in its configuration (CONFIG.FPW) stored in Visual FoxPro home folder.

You may ask another question if you need more info about resource file, its creation and possible location.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question