I have a directory (client_dir
) with a folder that is named "XXX - Long client name"
I want to save the full name of the folder ("XXX - Long client name") as a variable called client_name
. I can search for "XXX - Long client name" by matching the first 3 characters (XXX).I get the 3 characters somewhere else.
I tried using the re modudule, but I can't figure out how to get the actual full string. It only returns "XXX".
for closeout in os.listdir(closeout_dir):
project_id = closeout[:8]
client = project_id[0:3]
for x in os.listdir(client_dir):
client_name = re.search(client,x)
print(client_name)
print(type(client_name))
output:
<re.Match object; span=(0, 3), match='XXX'>
<class 're.Match'>
XXX
Another problem I've encountered is that when I add another folder to client_dir
called "YYY- another client name" it can't find my "XXX - Long client name" folder anymore. The output is:
None
<class 'NoneType'>