Jump to content
chipmonger

Possible Bug - FileExist checking for non-existent file

Recommended Posts

chipmonger

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
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
chipmonger

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
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
chipmonger

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
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
chipmonger

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
Bowmore

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
  • Like 1

"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
water

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

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
chipmonger

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
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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

    • BetaLeaf
      By BetaLeaf
      As the title says, when a script that is stored on a Google Drive File Stream drive is ran or compiled, it fails to work at all.
      Basically, Google Drive File Stream creates a G:\ drive where you can access all your files. The difference between this and Google Backup and Sync is your files are downloaded as needed rather than they always be downloaded and taking up storage. 
      How to Reproduce Bug
      1. Download and Install Google Drive File Stream
      2. Sign into Google Drive File Stream with a G Suite account. 
      3. Create a AutoIt Script and save it to Google Drive File Stream. (See attached file)
      4. Attempt to run or compile this AutoIt Script. 
       
      AutoIt appears to act like the script is (incorrectly) empty and ends immediately. (You can kind of tell based on file sizes from a successful and failed compile).
      I've also attached a Process Monitor log file. Hopefully someone can figure this out, because having to move the script out of the drive just to run or compile it is super annoying and I lose version revisioning Google Drive provides me.
      test.au3
      Logfile.PML
    • 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.
×