Thank you for that - really helpful. Yes, rsync just updates OneDrive from USB every 10 minutes or so. I'd got so wrapped up in testing this outside of OneDrive, that I hadn't thought of some of the things you mention. Looking at my OneDrive folder with lsof, OD has handles on files that aren't open anywhere else. So, your idea of renaming on the USB stick is best. Plus, she has quite a lot of data.

In terms of the time and things happening whilst the script runs, I have 1,200 files in my OD and this script found and renamed about 40 in 0.12 seconds, which seems OK. The time hog is lsof, which takes about 13 seconds to run. This seems ridiculous compared to linux, but apparently it's a mac thing.

Anyway, I'll create a temp file with the lsof output for the tree, then grep for the current filename before proceeding further. I understand grep will return 0 if it finds something.


In reply to Re^3: Easy way to check if a file is open needed. by Apt_Addiction
in thread Easy way to check if a file is open needed. by Apt_Addiction

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.