Python Forum
How to skip a folder directory in a loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to skip a folder directory in a loop
#1
Hi,

I have a code below:

path = "C:\User\Work\Identity\TestFolders"

def list_files(dir):
    r = []
    skip = ["NetIQ"]
    for root, dirs, files in os.walk(dir):
        if dirs in skip:
            continue
        else:
            for name in files:
                r.append(os.path.join(root, name))
    return r

print(list_files(path))
I want to skip "NetIQ" folder in my iteration, but I think I'm missing something there, please help.
Reply


Messages In This Thread
How to skip a folder directory in a loop - by mfkzolo - Nov-18-2020, 07:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through all files in a directory? Winfried 10 797 Apr-23-2024, 07:38 PM
Last Post: FortuneCoins
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 710 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  How to loop through all excel files and sheets in folder jadelola 1 4,796 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,690 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  need to skip password prompt, continue... tester_V 2 1,555 Oct-19-2021, 05:49 PM
Last Post: tester_V
  Delimiters - How to skip some html tags from being translate Melcu54 0 1,715 May-26-2021, 06:21 AM
Last Post: Melcu54
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,569 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  How to skip to a different line while importing a different script kat_gamer 2 2,319 Feb-03-2021, 04:10 AM
Last Post: deanhystad
  How to skip LinkedIn signup link using python script? Mangesh121 0 1,839 Aug-26-2020, 01:22 PM
Last Post: Mangesh121
  Python Cut/Copy paste file from folder to another folder rdDrp 4 5,267 Aug-19-2020, 12:40 PM
Last Post: rdDrp

Forum Jump:

User Panel Messages

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