0

I am using os.getcwd() to get user current directory. I want to check whether a file is in Desktop folder or not. But getcwd() function only returns username directory, like this /Users/macbookair, but I expect this:

/Users/macbookair/Desktop

I am using macOS Big Sur. Any help would be greatly appreciated. THanks

Nomore
  • 71
  • 1
  • 3

2 Answers2

0

You can use os.chdir('/Users/macbookair/Desktop') to change directory and os.listdir() - to list the file names in that directory.

shri_world
  • 36
  • 5
0
import os    #os module is helpful in interacting with os using python*
os.chdir("C:/Users/user/Desktop")    #change directory to desired path
print(os.listdir())    #list of files at desired path   

filename = str(input())    #typing name of file to check 
if filename in os.listdir():
        print(True)    #if filename exists 
else:
    print(False)    #if filename doesnot exists