I have a script that calculates the number of files in a folder, and if it is less than the maximum number, So this creates new file until the correct number is not. Ideally, old files are removed, new ones should be generated. The problem is that my code sometimes does not create a new file, if only one file is destroyed at a time, sometimes it will be used. If more than one is deleted at a time, it will always create new files.
import os cfcount = 0 maxcalls = 7 runs = 1 filecount = 0def callFile (channel, mccetry, time, wait, reference, ext): # stank returns callfile df getCount () : "File for files in" "" "number of callfiles in the directory" "calculation = 0 file = os.listdir (" c: \\ proc "): if os.path.isfile (" c: \\ proc \\ " + File): calculation = = 1 # when calculating the count of return (count) return run = 1 == 1: "" The main loop that runs till no people are left to call "filecount = getCount () Print (filename) lack_filecount = Maxcalls - filecount while lack_filecount> 0: cfcount + = 1 f = open ("c: \ proc \ callfile" + str (cfcount) + ".call", 'w') f.write (call file ("SIP F.close () print ("filecount:" + str (file count) print ("call file", "0", '0', '45', 'call-file-test', '200')) Number: "+ str (cfcount)" Lacking_filecount - = 1 I have been able to get it to work every time if I keep the print (file count) statement If I remove that statement, it sometimes works and sometimes it does not happen.
This is output
& gt; & Gt; & Gt; 0 Phonecount: Phone Number: Phonecount: Phone Number: 2 Phonecount: Phone Number: 3 Phonecards: Phone Number: 4 Phonecount: Phone Number: 5 Phonecount: Phone Number: 6 Number of Files: 0 Phone Number: 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7/7 7 7 7 7 7 7 Without print (file count) It seems that this number works about 9, then this new Files are left except, if only one has been removed, note that it is now Also prints a callfile number.
gt; & Gt; Call File Number: 1 Call File Number: 2 Call File Number: 3 Call File Number: 4 Call File Number: 5 Call File Number: 6 Call File Number: 7 Call File Number: 8 Callfile Number: 9 Call File Number: 10 Call File Number: 11 Call File Number: 12 Code> This output is output from the print (file) inside the loop. It is not working with that print statement yet.
call file number: 17 callfile 1 callon callfile 17 cal callfile 2 callal callfile 3.call callfile 4 callal callfile 5.call callfile 6 callal phonefile 1. Callfile17.call is being called as a race status between the file and the file appears as
os.listdir () Showing print output probably probably takes enough time just to "fix" your system. Why not change your logic, so that only call getCount () once, then creates the appropriate amount of files? filecount = getCount () lack_filecount = maxcalls - decrease of file count while_filecount & gt; 0: # Create file ... Absence_filcount - = 1 In addition, you have an infinite loop because you never set run inside the loop Have done
Comments
Post a Comment