Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
os.path.join - errors out
#1
Hi,
I'm trying to use 'os.walk' to find all the subdirectories and files in the root dir.
In the first "for" loop, the code generates an error Confused if I use:
os.path.join(root, dirs)
to get rid of an error I'm using a workaround :
root+'\\'+dr
I understand 'workaround' is not a good thing to use.
Here is the code.
import os
p = 'c:\\02'

for root, dirs, files in os.walk(p):
    for dr in dirs :
        #r = os.path.join(root, dirs)
        #print ("Dir/Path -- ", r)
        dp = root+'\\'+dr
        print (dp)
    for file in files:
        rf = os.path.join(root, file)
        print ('Roor+file-->> ',rf)
Any help is appriciated!
Thank you.
Reply


Messages In This Thread
os.path.join - errors out - by tester_V - Nov-22-2020, 07:15 AM
RE: os.path.join - errors out - by buran - Nov-22-2020, 08:36 AM
RE: os.path.join - errors out - by Axel_Erfurt - Nov-22-2020, 09:30 AM
RE: os.path.join - errors out - by tester_V - Nov-29-2020, 04:44 AM
RE: os.path.join - errors out - by DeaD_EyE - Nov-29-2020, 08:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  os.path.join() 'NoneType' confusion gowb0w 11 1,540 Sep-22-2023, 11:13 PM
Last Post: deanhystad
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,203 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  The difference between os.path.join( and os.sep.join( Pedroski55 2 9,436 Nov-17-2020, 08:38 AM
Last Post: Pedroski55
  os.path.join qmfoam 2 2,354 Nov-08-2020, 04:03 PM
Last Post: qmfoam
  SQL select join operation in python(Select.. join) pradeepkumarbe 1 2,232 Feb-14-2019, 08:34 PM
Last Post: woooee
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,740 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020