Thread: For and if

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Location
    Kansas
    Posts
    10
    Rep Power
    0

    For and if


    I have the following code that I am ruining. I can't figure out how to achieve what I want to do
    PHP Code:
    for i in movetoready:
        
    startsize os.path.getsize(i)
        
    time.sleep(3)
        
    endsize os.path.getsize(i)
            if 
    startsize endsize:
                
    findertools.move(printout ireadypath i)
            else:
                continue 
    move to ready is a list of files. I want to make sure that the application is done writing to the file before I copy it so I wait 3 seconds and if the file size is the same then I copy it. if it's not then I move on to the next file in the list. . . . . . what am I doing wrong????
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    25
    well your method of waiting 3 seconds isn't exactly the best, I would recommend using md5 to calculate if is the same file it was 3 seconds ago.

    However that isn't your problem, your problem is because when you say continue you are actually just telling the for loop part to go to the next file. So I recommend that you throw in an infanit loop like so:

    <code>
    for i in movetoready:
    while 1:
    startsize = os.path.getsize(i)
    time.sleep(3)
    endsize = os.path.getsize(i)
    if startsize = endsize:
    findertools.move(printout + i, readypath + i)
    else:
    break
    </code>

    thats ontested however the idea is where you need to go.
  4. #3
  5. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Norcross, GA (again)
    Posts
    1,805
    Rep Power
    1570
    As described here, the problem is essentially one of mutual exclusion: you need to ensure that your code does not try to access the file at the same time the other application does. Does the application in question lock the file at all, or can it be modified to do so? If so, then you can have the program simply check the lock, and either move on, or else wait on the lock.

    Or perhaps some more context would make the problem clearer. Can you tell us something of what the program is meant to accomplish, and what the other application is doing with the files? Is the application in question one you've written yourself (or one which you have source access to), or do you have to work with it as-is?

    EDIT: I'm obviously too tired to do this right now. Not only did I fail to notice the other, duplicate thread which gives a suitable answer to the problem, I also missed the basic problem with the comparison expression which the other thread addresses.
    Last edited by Schol-R-LEA; March 9th, 2006 at 01:44 AM.
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Location
    Kansas
    Posts
    10
    Rep Power
    0
    Thanks for the responses.


    I am willing to do the file size check the proper way (using MD5), but am unclear as to how to implement it. Could someone help me out? I am going to try to bang it out and see what happens.

    Any help would be great.

    Thanks Again Guys!

    btw: I am waiting for Renderman to finish making a tiff image. Sometimes it puts the file in the folder before it is completely done writing the file. Hence the image gets corrupt if I move it too fast.

IMN logo majestic logo threadwatch logo seochat tools logo