Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Why are there no errors when opening a filename that contains colons on Win10

by BillKSmith (Monsignor)
on Oct 10, 2019 at 15:32 UTC ( [id://11107314]=note: print w/replies, xml ) Need Help??


in reply to Why are there no errors when opening a filename that contains colons on Win10

You expect open to identify and reject all invalid names. It is not surprising that it is not always able to do this. A far better approach is to write a function that tests the name against the specification https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions, for windows file names.
Bill
  • Comment on Re: Why are there no errors when opening a filename that contains colons on Win10

Replies are listed 'Best First'.
Re^2: Why are there no errors when opening a filename that contains colons on Win10
by Lotus1 (Vicar) on Oct 11, 2019 at 14:24 UTC

    Hi Bill.

    You expect open to identify and reject all invalid names.

    What I actually said in my OP was:

    [...] before this I trusted the open to tell me if there was a problem with creating an output file.

    In this case with a colon in the filename, a file was created successfully and output was correctly written to the Alternate Data Stream as the other monks demonstrated to me. I bet I'm not the only one who had never heard of this newer feature of Windows. I was surprised and curious about this. My current script doesn't really need to completely validate the filenames since the names are not from user inputs. However I have coworkers who sometimes make clumsy changes so I try to make things bulletproof.

    Have you seen cases where the open() function did not correctly identify and reject invalid names?

      Four of your ten test cases were valid filenames which opened correctly. Five of the six invalid names correctly failed to open. For the sixth invalid name, windows took the strange corrective action you describe as a 'feature'. I do not have a clue what makes this name special. We have no idea how other invalid names may be handled. Code which makes any assumptions about invalid names is simply not 'bullet-proof'. Your simple test probably finds enough errors to be useful. You may even consider it an advantage that it allows some special cases that are not strictly valid.
      Bill

        The term 'bullet proof' can be relative. Compared to some of my co-workers who write scripts that read, write, copy, and move files blindly to UNC folders and drives that are sometimes full my scripts are very resilient and bullet proof.

        Thanks for your help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11107314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found