Python Forum
I need to copy all the directories that do not match the pattern
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need to copy all the directories that do not match the pattern
#5
Thank you for the code!
Do you think you could elaborate on why your snipped is working and my is not?
even if I add your regex it is not printing anything...
it seems exactly the same.

your code:
tofind = r'^[A-Z0-9]{8}_\d{4}$'
 
for d in ["_Y151029E_7345", "D151009EN_7295", "mydir","small_11","TST___3456","TST_3456","TST3456"]:
    if re.findall(tofind,d):
        print(f"{d} Matched")
    else:
        print(f"{d}  no match")
And I wrote (the directories names are the same):
import re
from pathlib import Path
tofind = r'^[A-Z0-9]{8}_\d{4}$'
for ed in Path('C:\\01\\TLogs').iterdir() :
    if ed.is_dir():
        rudir = Path(ed).parts[3]
        print(f" Dir_Name -{rudir}")
        if re.findall(tofind,rudir) :
            print(f" found -> {rudir}")
Reply


Messages In This Thread
RE: I need to copy all the directories that do not match the pattern - by tester_V - Feb-04-2022, 08:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 391 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Organization of project directories wotoko 3 582 Mar-02-2024, 03:34 PM
Last Post: Larz60+
  Listing directories (as a text file) kiwi99 1 912 Feb-17-2023, 12:58 PM
Last Post: Larz60+
  Regex pattern match WJSwan 2 1,385 Feb-07-2023, 04:52 AM
Last Post: WJSwan
  rename same file names in different directories elnk 0 773 Nov-04-2022, 05:23 PM
Last Post: elnk
  Python create directories within directories mcesmcsc 2 2,288 Dec-17-2019, 12:32 PM
Last Post: mcesmcsc
  Regular expression: match pattern at the end only Pavel_47 3 1,956 Nov-27-2019, 07:51 PM
Last Post: Gribouillis
  Shutil attempts to copy directories that don't exist ConsoleGeek 5 4,690 Oct-29-2019, 09:26 PM
Last Post: Gribouillis
  Accessing files in various directories and folders ccuny 2 2,246 May-08-2019, 12:11 PM
Last Post: ccuny
  Creating directories from two lists QueenSveta 2 2,846 Jun-22-2018, 09:33 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

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