chipmonger

Possible Bug - FileExist checking for non-existent file

11 posts in this topic

#1 ·  Posted (edited)

Have the following code snippet:

If not FileExists($ExchangeDir & $StockCSV) Then
            _FileWriteFromArray($ExchangeDir & $StockCSV, $YahooStockEntries)
        Else

When trying to do a check against the non-existent file 'PRN.csv', FileExists is evaluating as True.  This is not happening with other file names, directory structure is correct.

Any ideas?

Thanks

Chip

Edited by chipmonger

Share this post


Link to post
Share on other sites



Can you please give an example of the content of the two variables $ExchangeDir and $StockCSV that return an invalid result?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

For $StockCSV, "PRN.csv"

For $ExchangeDir, "C:\Documents and Settings\Chip\My Documents\Historical Data\Stock Activity\AMEX\"

Note that $ExchangeDir has been used unchanged on many other stocks/files with no issue.

The only thing I can thing of is 'PRN' being a character device.

Thanks,

Chip

Edited by chipmonger
Additional info

Share this post


Link to post
Share on other sites

How do you check that the file does not exist?
Maybe it is hidden and your Windows Explorer setting does not display hidden files.
Please open a CMD window and use Dir to check the directory.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I made a temporary file so PRN is the first entry processed.  The AAA directory was deleted prior to starting the program.  Other than storing a temporary file using a different filename in a different directory, this is the only place in the program where a file write occurs.

If I use my normal set of files and remove PRN from my list of entries to process, the program completes successfully.

Share this post


Link to post
Share on other sites

If you suspect that the name "PRN" is the culprit could you change the name and try again?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Without 'PRN' in my list to process, I've got over 6500 different filenames successfully processed and still going.

I've got to run out to meet family but will be back in the evening.

Thanks again,

Chip

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

There does seem to be a bug here or at least unexpected behaviour related to files name PRN It does not seem to matter what the extention is.

FileExists() is probable detecting the printer port PRN

;File and path do not exist
 $FolderA = "C:\ThisPathDoesNotExist\PRN.txt"
 $Exists = FileExists($FolderA)
 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Exists = ' & $Exists & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
 
 ;File and path do not exist
 $FolderB = "C:\ThisPathDoesNotExist\ABC.txt"
 $Exists = FileExists($FolderB)
 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Exists = ' & $Exists & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
 
 ;Path exist but file does not exist
 $FolderA = "C:\Temp\PRN.txt"
 $Exists = FileExists($FolderA)
 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Exists = ' & $Exists & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
 
 ;Path exist but file does not exist
 $FolderB = "C:\Temp\ABC.txt"
 $Exists = FileExists($FolderB)
 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Exists = ' & $Exists & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

 

EDIT: It also detects COM1.txt COM2.txt etc.

 

Edited by Bowmore
1 person likes this

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

I think the problem is caused by PRN being a reserved name as descrihed here.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I'll just remove PRN from my list of stocks to process.  Definitely looks to be a reserved word as Bowmore found.  This was the only stock symbol (for me) that caused an issue.

Chip

Share this post


Link to post
Share on other sites

You should avoid the following names as described in the MSDN article I posted above:
"The following names are reserved and can't be used for files or directories: CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, PRN, and NUL."


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • Byte11
      By Byte11
      WinSetState ("[CLASS:OpusApp]", "", @SW_SHOWMAXIMIZED) and WinSetState ("[CLASS:OpusApp]", "", @SW_MAXIMIZE) don't maximize the window.  Using WinSetState("[CLASS:OpusApp]","",@SW_RESTORE) allows me to maximize it about 15% of the time. I've tried using  WinMove("[active]",0,0,@Desktopwidth,@Desktopheight), but that only makes it worse. I've also tried putting in a sleep and maximizing it again. Does anyone have a solution?
      Here's my code:
      The startup script is intentionally commented, because I'm not testing it right now. The other comment is just for debugging when I need it. 
       
      UPDATE: When I run two instances of the program, it works almost all the time, but if I copy the code inside the else statement twice it doesn't work at all (despite the fact that it's running the same code just in one program vs two). I also noticed that when I run two instances of it, about 50% of the time when it opens both the windows, it also hits the windows button and types the letter d into the search box. Neither of these actions are in my code. I'm not really sure what's going on. 
    • distancesprinter
      By distancesprinter
      _ArrayDisplay($aArray, "Window Title", "1:", 0, Default, "Column") ; Expected results are rows 1 to the end of the array, all columns. The result is rows 0-1, all columns. The API reference is here:
      https://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayDisplay.htm
       
      Am I doing something wrong?
    • imitto
      By imitto
      Hi!
      I just playing around with _ArrayMin for my next project, but seems like it's not working. I think the code is OK, but I always get the value of $aArray[2][1], not col 2's lowest value (see attached image)

    • nss
      By nss
      Hi all.
       
      Because of me wondering if I could access the key/value pair arrays with the numbers as indexes, I have found out that the zeroth element for some reason doesn't return anything.
      Here's the example:
       
      local $r[2] $r["test1"]="hello" $r["test2"]="how are you" msgbox(64, $r[0], $r[1]) ; prints the ["test2"] but not ["test1"]. Is this even supposed to be a thing?  
       
      BTW, I haven't seen Autoit get updated since 2015; is it abandened or something?
      Any help/clarification appreciated.
    • TheDcoder
      By TheDcoder
      Hello everyone, I discovered a bug yesterday and I posted it at the bug tracker:
      I also made a simple script which can be used to reproduce the bug:
      CreateVariable() ConsoleWrite($sGlobalVariable & @CRLF) Func CreateVariable() Global $sGlobalVariable = "Foobar" EndFunc The bug was closed by @BrewManNH:
      While I partially agree with the above statement, My code was not practical enough... so @mLipok advised me to create a thread on the forums with practical code (Thanks!). That is the point of this thread, I am going to provide the code where I experience this bug/problem .
      I discovered this bug when I was working on one of my projects called "ProxAllium". When the main script finishes execution, Au3Check throws a nasty warning about "variable possibly used before declaration":

      As you can see, the variable is indeed being used after calling the function in which the variable is declared... The warning won't appear if I declare the function ABOVE the variable. As @BrewManNH said, Au3Check reads line by line... I think this should be changed, Au3Check should not throw warnings if the interpreter is able to run the code, at least most of the time anyway!
      So what do you guys think? Is this a valid bug?... and I request those who participate in the discussion not to discuss the code being "poor", that is another thing/thread in itself
      P.S I had already written this once but the forum editor decided to mess up and when I undid (Ctrl + Z) something... This is a poorly written version of that article, I was very frustrated while writing this!