<h3 dir="auto">System information</h3>
<ul dir="auto">
<li><strong>Have I written custom code (as opposed to using a stock example script provided in TensorFlow)</strong>: Yes.</li>
<li><strong>OS Platform and Distribution (e.g., Linux Ubuntu 16.04)</strong>: Windows 10 and macOS High Sierra 10.13.4</li>
<li><strong>TensorFlow installed from (source or binary)</strong>: <code class="notranslate">pip3 install --upgrade tensorflow</code></li>
<li><strong>TensorFlow version (use command below)</strong>: 1.8.0</li>
<li><strong>Python version</strong>: 3.6.5</li>
<li><strong>Bazel version</strong>: N/A</li>
<li><strong>CUDA/cuDNN version</strong>: N/A</li>
<li><strong>GPU model and memory</strong>: N/A</li>
<li><strong>Exact command to reproduce</strong>: In source code</li>
</ul>
<h3 dir="auto">Describe the problem</h3>
<p dir="auto">gfile.Glob() works recursively in Windows, but not in Unix-based systems.<br>
Ideally, they should work the same way.</p>
<h3 dir="auto">Source code</h3>
<p dir="auto">Stand in a root folder, create subfolder and add a image.jpg in the subfolder.<br>
Then start python and run:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from tensorflow.python.platform import gfile
print(gfile.Glob(&quot;./*.jpg&quot;))"><pre class="notranslate"><code class="notranslate">from tensorflow.python.platform import gfile
print(gfile.Glob("./*.jpg"))
</code></pre></div>
<p dir="auto">In Windows, you will get <code class="notranslate">[".\\subfolder\\image.jpg"]</code>.<br>
In Unix, you will get <code class="notranslate">[]</code>.</p>
<h3 dir="auto">System information</h3>
<p dir="auto">Environment:</p>
<ul dir="auto">
<li>
<p dir="auto"><strong>Python 3.6.2</strong></p>
</li>
<li>
<p dir="auto"><strong>Tensorflow 'v1.8.0-0-g93bc2e2072' 1.8.0</strong></p>
</li>
<li>
<p dir="auto"><strong>OS : Windows 7</strong></p>
</li>
<li>
<p dir="auto"><strong>Exact command to reproduce</strong>:</p>
</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" &gt; ls -R
.:
example/

./example:
subdir/

./example/subdir:
file1  file2


&gt; python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import tensorflow as tf
&gt;&gt;&gt; tf.gfile.Glob(&quot;example/*&quot;)
['example\\subdir', 'example\\subdir\\file1', 'example\\subdir\\file2']
"><pre class="notranslate"><code class="notranslate"> &gt; ls -R
.:
example/

./example:
subdir/

./example/subdir:
file1  file2


&gt; python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import tensorflow as tf
&gt;&gt;&gt; tf.gfile.Glob("example/*")
['example\\subdir', 'example\\subdir\\file1', 'example\\subdir\\file2']

</code></pre></div>
<h3 dir="auto">Describe the problem</h3>
<p dir="auto">Behaviour of <em>tf.gfile.Glob</em> is different on Windows and Linux-based (POSIX) systems.<br>
On Windows, the result includes all files and sub-directories of the matching pattern (=&gt; recursive)<br>
On Linux, the result includes only files and directories matched by the pattern (=&gt; not recursive)</p>
<p dir="auto">As an example, given the directory structure above, I have the following result:</p>
<ul dir="auto">
<li>Windows</li>
</ul>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; tf.gfile.Glob(&quot;example/*&quot;)
['example\\subdir', 'example\\subdir\\file1', 'example\\subdir\\file2']"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">tf</span>.<span class="pl-s1">gfile</span>.<span class="pl-v">Glob</span>(<span class="pl-s">"example/*"</span>)
[<span class="pl-s">'example<span class="pl-cce">\\</span>subdir'</span>, <span class="pl-s">'example<span class="pl-cce">\\</span>subdir<span class="pl-cce">\\</span>file1'</span>, <span class="pl-s">'example<span class="pl-cce">\\</span>subdir<span class="pl-cce">\\</span>file2'</span>]</pre></div>
<ul dir="auto">
<li>Linux-based systems</li>
</ul>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; tf.gfile.Glob(&quot;example/*&quot;)
['example/subdir']"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">tf</span>.<span class="pl-s1">gfile</span>.<span class="pl-v">Glob</span>(<span class="pl-s">"example/*"</span>)
[<span class="pl-s">'example/subdir'</span>]</pre></div>
<p dir="auto">The result returned on Windows platform is clearly wrong.</p>
<p dir="auto">This has an impact on my application because I do something like <code class="notranslate">[my_list]=tf.gfile.Glob(pattern)</code> and it doesn't work on Windows whereas it works on Linux.<br>
Error on Windows is <code class="notranslate">ValueError: too many values to unpack </code></p>
<h3 dir="auto">Source code</h3>
<p dir="auto">I tracked down the issue in TF code and it is related to how <em>GetMatchingPaths</em> works. See difference between <a href="https://github.com/tensorflow/tensorflow/blob/e7f158858479400f17a1b6351e9827e3aa83e7ff/tensorflow/core/platform/windows/windows_file_system.cc">Windows implementation</a> and <a href="https://github.com/tensorflow/tensorflow/blob/e7f158858479400f17a1b6351e9827e3aa83e7ff/tensorflow/core/platform/posix/posix_file_system.cc">POSIX implementation</a>.<br>
Both of them refer to <a href="https://github.com/tensorflow/tensorflow/blob/6ba9573a702ea9e1290517cce4e5f73a14552ad9/tensorflow/core/platform/file_system_helper.cc">internal::GetMatchingPaths</a> which seems to be the root cause of the issue.</p>