Ignore this question. It is completely different than the actual question I needed to ask. For the people who already answered the question, I'm sorry. Hopefully this will help someone in the future, though.
Read the new thread here: Opening files found from os.listdir() and comparing lines inside?
Basically, I'm running os.listdir() to get a listing of files, and then trying to compare if two different files have similar names. How would I go about this?
Basically, the code is currently this:
config_dir = "/etc/netctl/"
profiles = os.listdir(config_dir)
for i in profiles:
if os.path.isfile(config_dir + i):
if i in i:
print "True"
else:
pass
I'm not sure what I would use to check for similarities in the names, though. However, I know "if i in i" is just checking for the same word... but I don't know how I would go about saving the last one...
I also tried:
i2 = ""
profiles = os.listdir(config_dir)
for i in profiles:
if os.path.isfile(config_dir + i):
if i2 == "":
i2 = i
print i2
elif i2 == i:
continue
if i2 in i:
print "true"
else:
pass
I think I might be overthinking this, though. This is the output of os.listdir:
['hooks', 'interfaces', 'examples', 'ddwrt', 'MomAndKids_wifiz', 'backups', 'MomAndKids']
The files are ddwrt MomAndKids_wifiz and MomAndKids. Basically, I want it to detect that the names "MomAndKids" and "MomAndKids_wifiz" is similar, and then return True.