Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2002
    Location
    Nashville TN
    Posts
    328

    File.DoesExist() False Positive

    Some people might pick this one apart but here is the deal, if you pass a variable into the File.DoesExist() and it is equal to a valid folder (NO FILE) it returns "true". I would like to summit this is wrong since there is “no file it must be false”, if I wanted to test for a folder I would use Folder.DoesExist.

    Maybe an option in the File.DoesExist() function for "must be a file" = true/false or something. I have a pick box but if user types in a folder with no file its testing good because the folder is valid, but I crashing later in the script because there did not input a file. I think I can code around this for now suggests are always welcome, but I would summit this to IR as a bug.

  2. #2
    Join Date
    Mar 2005
    Location
    WA 'wait a while' - Australia
    Posts
    872
    try this 'one way to do' it test workaround:
    (I believe the 'issue' is NTFS file system related)

    place function in Globals if ya want

    Code:
    function Is_aValidFile(sIn)
    --[[attempt to verify target is 'valid' and is of type: 'file'
    	notes:
    	- 'folders' on 'ntfs' formatted 'storage devices\sources' are in reality 'place holder' files  under the hood
    	-  ( which is why several 'file' related actions can work on 'ntfs'  'folders' - and do not work on 'fat32' and ealier) 
    	- a valid 'folder' should return a 'file size' of: 0 bytes ]]
    	 
    if sIn then
    	if (not Folder.DoesExist(sIn)) then
    	local nsize = File.GetSize(sIn); -- 'file' must be greater 0 bytes
    	local nerror = Application.GetLastError();
    		if ((nsize > 0) and (nerror == 0)) then	
    			return true; --is valid and of type: 'file'		
    		end
    	end	
    end
    
    return false; --is of type 'folder'  or an error occurred 
    
    end

    to call the function test calls - place below where suitable


    Code:
    --Example diagnostic test call(s)
    
    --(manually create in: yourlocaltempfolder\folder\file   structure as below - then run a few test calls
    
    local sTarget_fl = _TempFolder.."\\test.txt\\test.txt";--try this one(make sure the 'real file' is > 0 bytes)
    --local sTarget_fl = _TempFolder.."\\test.txt"; --now try this one(make sure is a 'real folder')
    
    if (not Is_aValidFile(sTarget_fl)) then
    --an error occurred or in theory is of type: 'folder'
    --do some stuff here - test eg: 
    	Dialog.Message("File validation:  Failed", sTarget_fl);
    else
    	Dialog.Message("File validation:  Passed", sTarget_fl);	
    end

    tweak to suit once you are satisfied is reliable enough for your purposes

  3. #3
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    Note that checking the size will give false positives on actual 0-byte files, which are fairly common.
    --[[ Indigo Rose Software Developer ]]

  4. #4
    Join Date
    Jan 2002
    Location
    Nashville TN
    Posts
    328
    Eagle,

    Thanks for the reply I see what your doing, I like, and a good idea, I reworked my installer to reduce the change of this happening, I might add your code as well really prevent it, Thanks for the sample.

    Lorne,

    Thanks for the added info. File should never be 0 k (famous last words).

Similar Threads

  1. media player plugin question "3"
    By jackdaniels in forum AutoPlay Media Studio 6.0
    Replies: 4
    Last Post: 03-06-2007, 07:42 AM
  2. HTML/PHP cleanner
    By Mikhail in forum AutoPlay Media Studio 7.5 Examples
    Replies: 0
    Last Post: 09-08-2006, 08:41 PM
  3. Resetting Variables
    By srussell in forum AutoPlay Media Studio 6.0
    Replies: 2
    Last Post: 11-30-2005, 08:01 PM
  4. 5003 woes
    By John_Klassek in forum AutoPlay Media Studio 5.0
    Replies: 5
    Last Post: 12-30-2003, 04:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts