Announcement

Collapse
No announcement yet.

ISFILE made to fail example

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mike Doty
    replied
    If you have no rights ( /P....:n" ) to access the folder, why would you expect PB to be able to locate a file inside it?
    PowerBASIC program will OPEN and GET if the file exists when rights /P Everyone:N
    GETATTR returns 32 and ISFILE returns 0.(not found) with the file c:\sql\bin\1\test.txt
    Code:
    DECLARE FUNCTION MakeSureDirectoryPathExists LIB "IMAGEHLP.DLL" ALIAS "MakeSureDirectoryPathExists" (DirPath AS ASCIIZ) AS LONG
    
    FUNCTION PBMAIN AS LONG
     LOCAL sFile   AS STRING
     LOCAL sFolder AS STRING
     LOCAL sData   AS STRING
     sFile   = "test.txt"
     sFolder = "c:\sql\bin\1\"
     sData   = "This is the test data"
     MakeSure sFolder
    
     'enable full access
     UnlockFolder sFolder
     KILL sFolder + sFile:ERRCLEAR
     OPEN sFolder + sFile FOR BINARY AS #1
     IF ERR THEN ? "Open failed" + STR$(ERRCLEAR)
     PUT$ #1,sData + " at " + TIME$
     IF ERR THEN ? "Put failed" + STR$(ERRCLEAR)
     CLOSE #1
    
     'disable modify access
     LockFolder sFolder
     IF ISFILE (sFolder + sFile) = 0 THEN ? "ISFILE DID NOT FIND FILE"
     IF GETATTR(sFolder + sFile) = 0 THEN ? "GETATTR DID NOT FIND FILE"
     OPEN sFolder + sFile FOR BINARY AS #1
     IF ERR THEN ? "Open failed while lock" + STR$(ERRCLEAR)
     PUT$ #1,sData
     IF ERR THEN ? "PUT$ failed while lock" + STR$(ERRCLEAR)
     SEEK #1,1
     GET$ #1,LOF(1),sData
     IF ERR THEN ? "Get$ failed while lock" + STR$(ERRCLEAR)
     ? sData
     CLOSE #1
    
     UnLockFolder sFolder
    END FUNCTION
    
    FUNCTION MakeSure(BYVAL sFolder AS STRING) AS LONG
     LOCAL result AS LONG
     IF RIGHT$(sFolder,1) <> "\" THEN sFolder+="\"
     FUNCTION = MakeSureDirectoryPathExists(BYCOPY sFolder)
    END FUNCTION
    
    SUB LockFolder(BYVAL sFolder AS STRING)
     IF RIGHT$(sFolder,1) = "\" THEN sFolder = LEFT$(sFolder,-1)
     SHELL ENVIRON$("COMSPEC") + " /C echo y| cacls.exe " + sFolder + " /P everyone:n",0
    END SUB
    
    SUB UnLockFolder(BYVAL sFolder AS STRING)
     IF RIGHT$(sFolder,1) = "\" THEN sFolder = LEFT$(sFolder,-1)
     SHELL ENVIRON$("COMSPEC") + " /C echo y| cacls.exe " + sFolder + " /P everyone:f",0
    END SUB'

    Leave a comment:


  • Stuart McLachlan
    replied
    https://docs.microsoft.com/en-us/win...commands/cacls

    This command has been deprecated. Please use icacls instead.

    That said:

    If you have no rights ( /P....:n" ) to access the folder, why would you expect PB to be able to locate a file inside it?

    The question should not be why does ISFILE not find the file.
    It should be how does GETATTR find the file???

    I can't see anything files in the folder using Explorer or DIR from a console even if I'm in the folder. and if I'm not already in the folder, I can't access it

    Leave a comment:


  • Mike Doty
    started a topic ISFILE made to fail example

    ISFILE made to fail example

    ISFILE fails if everyone permission is set to no finding EXE.FULL$
    GETATTR works finding EXE.FULL$
    ISFILE Function
    The file subsystem IS checked TO determine whether the file specified by FileName currently exists.
    IF it IS found IN ANY form (HIDDEN, system, READ-ONLY, etc.), the value true (-1) IS returned.
    Otherwise, the value false (0) IS returned.
    Filename IS an unambiguous file NAME, which may NOT contain an asterisk (*) OR query (?).
    IF it contains one OR more OF those characters, the FUNCTION always returns false (0).
    Warning: Do not run this code without calling UnlockFolder at the end.
    Code:
    FUNCTION PBMAIN AS LONG
     LockFolder EXE.PATH$
     IF ISFILE(EXE.FULL$)  THEN ? EXE.FULL$,,"ISFILE  correct"  ELSE ? EXE.FULL$,%MB_ICONERROR,"ISFILE could not find"
     IF GETATTR(EXE.FULL$) THEN ? EXE.FULL$,,"GETATTR correct" ELSE ? EXE.FULL$,%MB_ICONERROR,"GETATTR could not find"
     UnlockFolder EXE.PATH$ 'REQUIRED or you will have to unlock manually or using UnLockFolder
    END FUNCTION
    
    SUB LockFolder(BYVAL sFolder AS STRING)
     IF RIGHT$(sFolder,1) = "\" THEN sFolder = LEFT$(sFolder,-1)
     SHELL ENVIRON$("COMSPEC") + " /C echo y| cacls.exe " + sFolder + " /P everyone:n",0
    END SUB
    
    SUB UnLockFolder(BYVAL sFolder AS STRING)
     IF RIGHT$(sFolder,1) = "\" THEN sFolder = LEFT$(sFolder,-1)
     SHELL ENVIRON$("COMSPEC") + " /C echo y| cacls.exe " + sFolder + " /P everyone:f",0
    END SUB
    I have sent a link to this thread to PowerBASIC support.


    Compile in another folder (if you are locked out) to unlock a folder
    Code:
    FUNCTION PBMAIN AS LONG
     LOCAL sFolder AS STRING
     sFolder = INPUTBOX$("Please type path","Unlock Folder")
     UnlockFolder sFolder
    END FUNCTION
    
    SUB LockFolder(BYVAL sFolder AS STRING)
     IF RIGHT$(sFolder,1) = "\" THEN sFolder = LEFT$(sFolder,-1)
     SHELL ENVIRON$("COMSPEC") + " /C echo y| cacls.exe " + sFolder + " /P everyone:n",0
    END SUB
    
    SUB UnLockFolder(BYVAL sFolder AS STRING)
     IF RIGHT$(sFolder,1) = "\" THEN sFolder = LEFT$(sFolder,-1)
     SHELL ENVIRON$("COMSPEC") + " /C echo y| cacls.exe " + sFolder + " /P everyone:f",0
    END SUB
Working...
X