Jump to content

NotADirectoryError Python error

RexLee
Go to solution Solved by fizzlesticks,

.ds_store is a file, not a folder. You're calling the line

img_list = os.listdir(img_fold_A)

for everything in the folder, which of course causes an error when you call it with a file.

 

You could either delete the .ds_store file at the start or add a check to skip files.

I am running this code here.

Even though I am giving the full path(/Users/rexlee/Desktop/A) to the parser it gives me:

NotADirectoryError: [Errno 20] Not a directory: '/Users/rexlee/Desktop/Learn/A/.DS_Store'

Why is it not able to find the directory.

Link to comment
Share on other sites

Link to post
Share on other sites

If im not wrong, a directory is a folder.

You are providing the code for an application/file and the system is expecting a directory(folder).

Link to comment
Share on other sites

Link to post
Share on other sites

Yes this is what the folder looks like from finder.

 

Screen Shot 2017-04-16 at 8.41.53 PM.png

Link to comment
Share on other sites

Link to post
Share on other sites

are you sure .DS_Store is a folder and not a file?

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

I'm not sure. What I entered into the terminal was:

python combine_A_and_B.py --fold_A /Users/rexlee/Desktop/A --fold_B /Users/rexlee/Desktop/B --fold_AB /Users/rexlee/Desktop/AB

 

Link to comment
Share on other sites

Link to post
Share on other sites

.ds_store is a file, not a folder. You're calling the line

img_list = os.listdir(img_fold_A)

for everything in the folder, which of course causes an error when you call it with a file.

 

You could either delete the .ds_store file at the start or add a check to skip files.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks it worked after I deleted the .ds_store file. Why does it cause the error though? Isn't /Users/rexlee/Desktop/A a folder when I pass it?

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, RexLee said:

Thanks it worked after I deleted the .ds_store file. Why does it cause the error though? Isn't /Users/rexlee/Desktop/A a folder when I pass it?

In the line 

splits = os.listdir(args.fold_A)

yes that works fine because "/Users/rexlee/Desktop/A" is a folder.

Inside the loop when you do 

img_fold_A = os.path.join(args.fold_A, sp)
img_fold_B = os.path.join(args.fold_B, sp)
img_list = os.listdir(img_fold_A)

args.fold_A = "/Users/rexlee/Desktop/A"

sp = ".DS_Store"

which makes

img_fold_A = "/Users/rexlee/Desktop/A/.DS_Store" which is a file.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Oh I get it now. I thought it was the whole folder that was wrong. Thanks~

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×