Home > Back-end >  Add an empty string to a path
Add an empty string to a path

Time:12-10

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.

CodePudding user response:

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"

  • Related