My script is supposed to go through a folder and search all the file names and split the text at the hyphen. My files are named, filename (hyphen) badge number, so example 20190101-B1234. I want to type in the badge number (numbers after the hyphen in file name).
So in this example I would have to search “B1234” and it should open folder “20190101-B1234”, but its not. Its opening the first folder in the directory every time.
So in this example I would have to search “B1234” and it should open folder “20190101-B1234”, but its not. Its opening the first folder in the directory every time.
import subprocess
import os, sys
text = input("Badge number: ")
splitstring=(text.split("-"))
splitstring.pop(0) #split the text
paths = [ "\\\\Server\\case\\test\\" ] #test folder
print("Searching ... \n")
found = 0
for i in range(0, len(paths)):
path = paths[i]
dirs = os.listdir(path)
for fil in dirs:
filstring=(text.split("-"))
filstring.pop(0)
if filstring == splitstring:
print("Path to Case File: " + path + fil)
openString = 'explorer "'+ path+ fil + '"'
subprocess.Popen(openString)
found = found + 1
break
if found == 0:
print("Unable to find Case File for " + text)
print("Check spelling and try agian.")
else:
print("\n")\
