Using pathlib/os.path etc correctly
<p>I was wondering how to use the os.path and pathlib correctly. I'm supposed to search for a directory(which I already did) and then after that enter a letter and space and it will decide what it will do.</p>

<p>import os
import os.path
import shutil
from pathlib import Path</p>

<pre><code>def search_files():
    directory = input()
    exist = Path(directory)
    if exist.exists():
        return directory
    else:
        print("Error")
        print("Try again: ")
        return search_files()





def search_characteristics(directory):
    interesting = input()
    exist = os.path.exists(directory)
    if interesting[0] == 'N':
        return os.path.join(directory, interesting)
    else:
        print("Error")
        return search_characteristics()



if __name__ == '__main__':
    directory = input()
    search_files()
    search_characteristics(directory)
</code></pre>

<p>For this as you can see, search_files looks for a directory which works. 
The next part is the one where I'm confused. Basically after it searches for a directory, C:\Program Files or something, I would enter N in the new line to search for what I want in the directory. </p>

<p>Say like </p>

<blockquote>
  <p>C:\Users\Desktop\stuff</p>
  
  <p>N something.txt</p>
</blockquote>

<p>The N would look for the exact name of the file. </p>

<p>Am I doing it correctly or is there another way to do it?</p>

<p>This script will do what you want. Along with using the result of your directory search function for the next call, I also changed the compare to use <code>.startswith</code> so that a emtpy string response doesn't crash the program.</p>

<pre><code>import os
from pathlib import *

def search_files():
    directory = input()
    exist = Path(directory)
    if exist.exists():
        return directory
    else:
        print("Error")
        print("Try again: ")
        return search_files()


def search_characteristics(directory):
    interesting = input()
    exist = os.path.exists(directory)
    if interesting.startswith('N'):
        return os.path.join(directory, interesting)
    else:
        print("Error")
        return search_characteristics(directory)

if __name__ == '__main__':
    directory = search_files()
    fn = search_characteristics(directory)
    print(fn)
</code></pre>

python