Jump to content

Possible Bug - FileExist checking for non-existent file


Recommended Posts

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
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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.

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

"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

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

×
×
  • Create New...