Today We are Going To Solve “IsADirectoryError: [Errno 21] Is a directory: It is a file” in Python. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.
Contents
How to Fix “IsADirectoryError: [Errno 21] Is a directory: It is a file” Error?
- How to Fix “IsADirectoryError: [Errno 21] Is a directory: It is a file” Error?
To Fix “IsADirectoryError: [Errno 21] Is a directory: It is a file” Error just Use os.walk() function. Just use os.walk() function to solve this issue.
data_paths = [os.path.join(pth, f) [for pth, dirs, files in os.walk(in_dir) for f in files]
- “IsADirectoryError: [Errno 21] Is a directory: It is a file”
To Fix “IsADirectoryError: [Errno 21] Is a directory: It is a file” Error just Run the commands. Just run the below command to solve your issue.
data_paths = [os.path.join(in_dir, f) for f in os.listdir(in_dir)] data_paths = [i for i in data_paths if os.path.isfile(i)]
Solution 1 : Use os.walk() function
Just use os.walk() function to solve this issue.
data_paths = [os.path.join(pth, f)
[for pth, dirs, files in os.walk(in_dir) for f in files]
Solution 2 : Run the commands
Just run the below command to solve your issue.
data_paths = [os.path.join(in_dir, f) for f in os.listdir(in_dir)]
data_paths = [i for i in data_paths if os.path.isfile(i)]
Conclusion
So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.
Also Read These Solutions
- SyntaxError: import declarations may only appear at top level of a module
- TypeError: firebase.auth is not a function
- SQLSTATE[HY000]: General error: 1364 Field ‘name’ doesn’t have a default value laravel 5.5
- no python at “C:\Users\AccountName\AppData\Local\Programs\Python\Python38-32\python.exe” error in VsCode
- Jest: Cannot spy the property because it is not a function; undefined given instead