Add an empty string to a path

Question:

I want to add an empty string to a path.
Let me place my code so you can better understand.

inpDir = r"C:/User/Folder"

flag = 1

if flag == 1:
    path_str = ["/1", "/5", "/12", "/54", "/76"]
else:
    path_str = []

for i in path_str:
    inpDir = inpDir + i + "/img"
    do all the process now for each subfolders

So if flag = 1 the script will do the the process in each subfolders (for example in C:/User/Folder/1/img), while if I put the falg = 0 I want that the process is done in (C:/User/Folder/img), how can I do it? Putting path_str = [] doesn’t allow me to enter the for (it should be executed one time with flag=0), while for flag=1 for each subfolders.

Thanks in advance.

Asked By: TFAE

||

Answers:

It looks like cheat-mode but it has the advantage of keeping the program logic unchanged.

else:
    path_str = ["./"]

Which gives "C:/User/Folder/./img" that is equivalent to "C:/User/Folder/img"

Answered By: 0x0fba
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.