python: Mac can read all files in a directory but Windows can't?
Question: This is probably a naive question since I am absolutely a newbie to python...

I was trying to read a bunch of .txt files from a directory using Mac, and it
worked perfectly, obtaining all the files without any exceptions.

But then I realized I needed to switch to another Window computer to do the
computing... and it just wouldn't read all the files.

Here is an illustration:

    
    
    import numpy as np
    import glob
    import os
    from __future__ import print_function
    
    # read all .txt files in directory
    
    names = []
    for file in os.listdir("Data/text/film/topy/"):
        if file.endswith(".txt"):
            print(file)
            names.append(file)
    
    scripts = [[] for _ in range(len(names)) ]
    for i in xrange(len(names)):
        scripts[i] = np.genfromtxt("Data/text/film/topy/"+names[i],  delimiter="\t",dtype=character,skip_header=1)
    

names is a list for the .txt file names and scripts is a list comprehension
for file contents.

There should be 365 files in there, and with Mac I could read all of them, but
with Windows, only 357 files could be read...

the file names are like these:

    
    
    l_10-Things-I-Hate-About-You.txt
    l_12.txt
    l_17-Again.txt
    l_30-Minutes-or-Less.txt
    l_48-Hrs..txt
    l_50-50.txt
    l_500-Days-of-Summer.txt
    l_A-Serious-Man.txt
    l_Adaptation.txt
    l_Addams-Family,-The.txt
    l_Adventures-of-Buckaroo-Banzai-Across-the-Eighth-Dimension,-The.txt
    l_After-School-Special.txt
    

......

Is there certain files name that prevents Windows from reading? Does anyone
know the difference and why is it? Super appreciated!!


Answer: Windows has restrictions on the characters that can be contained in a file
name. From [Naming Files, Paths, and
Namespaces](https://msdn.microsoft.com/en-
us/library/windows/desktop/aa365247%28v=vs.85%29.aspx):

> Use any character in the current code page for a name, including Unicode
> characters and characters in the extended character set (128–255), except
> for the following:
>
> The following reserved characters:
>
>   * `<` (less than)
>   * `>` (greater than)
>   * `:` (colon)
>   * `"` (double quote)
>   * `/` (forward slash)
>   * `\` (backslash)
>   * `|` (vertical bar or pipe)
>   * `?` (question mark)
>   * `*` (asterisk)
>
>   * Integer value zero, sometimes referred to as the ASCII NUL character.
>
>   * Characters whose integer representations are in the range from 1 through
> 31, except for alternate data streams where these characters are allowed.
> For more information about file streams, see File Streams.
>

If any of your file names contains one of these characters, it will be
unreadable on a Windows system.

