Print/list Only 5 Entries From Os.walk In Python
My Goal - To list only 5 entries when using OS walk. So far I have only been able to get a list of everything that I find using OS.Walk or only list one entry. (By using the return
Solution 1:
Try this:
def playmusic(name):
for root, dirs, files in os.walk('E:\\', followlinks=True):
for file in files[0:5]: #You show the first five only
if name in file:
vlc='C:/Program Files/VideoLAN/VLC/vlc.exe'
music=str(os.path.join(root,file))
print(music)
#subprocess.Popen([vlc, music])
#return
print("Finish")
input()
try:
s=raw_input("name: ")
playmusic(s)
except Exception as e:
print(e)
print("Error")
Post a Comment for "Print/list Only 5 Entries From Os.walk In Python"