I have written the following code to get path for files in sub_folder.
import os
os.chdir('C:\Users\mike\Desktop\a')
base_dir = os.getcwd()
sub_dirs = [os.path.join(base_dir, d) for d in os.listdir(base_dir)]
for i in os.listdir(sub_dirs):
path = [os.path.join(sub_dirs), i]
but it does not work and I get this error: Traceback (most recent call last): File "C:\Users\mike\Desktop\mine1.py", line 6, in for m in os.listdir(sub_dirs): TypeError: coercing to Unicode: need string or buffer, list found
what is the problem?
Cheers
os.path.join(sub_dirs)to do? - Anand S Kumara,b,forn(possibly a few others). With a non-raw string,\bis the ASCII backspace character, not a backslash followed byb, and similar issues apply to the other examples. It's best to be safe and always use raw strings, e.g., in your example,r'C:\Users\mike\Desktop\a'(note leadingrbefore open quote). - ShadowRanger