Alright, so I'm writing a program to help connect to wireless networks. I have most of it down (in fact, it's complete. I'm just working on extra features.)
I'm writing a GUI frontend for a wireless network connection backend called NetCTL for the Arch Linux Operating System. Basically, people can manually create profiles and name it whatever they want (i.e., "asdfasdfasdf"), but mine will ALWAYS generate $NetworkSSID_wifiz.
However, every file will have one line in it that would be able to determine if it is for the same network.
The line is:
ESSID='$NetworkSSID'
So how would I go about opening each file that appears in os.listdir and checking if those two files have the same line (while not producing too much overhead, preferably.)?
All profiles are saved in /etc/netctl whether generated by my program, or by the user.
Sample files:
User Created:
Description='A simple WPA encrypted wireless connection'
Interface=wlp2s0
Connection=wireless
Security=wpa
IP=dhcp
ESSID='MomAndKids'
# Prepend hexadecimal keys with \"
# If your key starts with ", write it as '""<key>"'
# See also: the section on special quoting rules in netctl.profile(5)
Key='########'
# Uncomment this if your ssid is hidden
#Hidden=yes
Created by my program:
Description='A profile generated by WiFiz for MomAndKids'
Interface=wlp2s0
Connection=wireless
Security=wpa
ESSID='MomAndKids'
Key='#######'
IP=dhcp
Sample os.listdir output:
['hooks', 'interfaces', 'examples', 'ddwrt', 'MomAndKids_wifiz', 'backups', 'MomAndKids']
This should work for you:
Or you could try
os.walk
if you want to descend into the directories;