Combining paths using os.path.join
<p>I was wondering how you correctly use os.path. Basically what I'm trying to do is ask the user for a directory and after that, they type a letter (<code>N</code> in this case), and then a filename in the directory and it will combine the directory with the file.</p>

<p>For example:</p>

<pre><code>C:\Desktop
</code></pre>

<p>and</p>

<pre><code>N hello
</code></pre>

<p>The final result produced would be C:\Desktop\hello.</p>

<pre><code>import os
import os.path
import shutil
from pathlib import Path
</code></pre>

<p>':
        directory = input()
        search_files()
        directory1=search_characteristics(directory)
        #print(directory1)</p>

<p>What am I doing wrong?</p>

<p>Here, this should work.</p>

<pre><code>def search_characteristics(directory):
    interesting = input()
    interesting = interesting.split(" ")
    if (interesting[0] == 'N'):
        directory += (os.sep + interesting[1])
        print(directory)
    elif interesting.startswith('E'):
        return os.path.splitext(directory,'')
    else:
        print("Error")
        return search_characteristics(directory)
</code></pre>

<p>If you have to use os.path.join then you can replace the line with os.sep with:</p>

<pre><code>directory = os.path.join(directory, interesting[1])
</code></pre>

python python-3.4 os.path