Click here to Skip to main content
15,918,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Currently I loop through all the files in the folder by using:

Python
for eachFile in os.listdir(savePath):


Whats a quick way to look at the only the first 50 files? I am troubleshooting my program and looking at all ~2000 files in the folder takes too much time to loop through.

if I can reduce the number of files I look at I can debug much faster. The following feels clunky... any suggestions on making this ultra efficient? Thank you!

Python
g = []
for eachFile in os.listdir(savePath):
    j = eachFile.strip(".tx")
    g.append(j)

For x in range(0,50):
    

    #Created a list for each file
    w = list(reversed(list(open(savePath + '/' + g[x]))))
Posted

1 solution

point it at a directory with fewer files in it?

or have a sacrificial dir that points to the 'real' dir or your 'reduced' dir (as appropriate) using mklink[^]?
 
Share this answer
 
Comments
PythonHeadBanger 2-Dec-15 22:37pm    
Yeah, that would have been smarter to create a test folder...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900