Recursive check for locked files I'll have to move a large network directory with many sub-directories and thousands of files. A number of users work on these files on a daily basis. OS is windows.

The move itself (copy and delete) I'll do using robocopy.

Before starting the batch process of moving, I would like to check for locked files. In case some files or folders are locked, I won't bother starting the process.

robocopy has a dry run switch, but that doesn't check for locked files which would lead to an unsuccessful run.

I quickly came up with something like the below, in Python:

import os

is_locked=list()

for root, dirnames, filenames in os.walk('path/to/directory'):
    for filename in filenames:
        full_filename = os.path.join(root, filename)
        try:
            pf = open(full_filename, 'a')
            pf.close()
        except PermissionError:
            is_locked.append(full_filename)


Your opinion whether this is a good or bad way of doing it? Any general comment? 
Performance, etc?

Is it harmless to be opening these files?

--- edit ---

Summary of the most relevant comments:


Break the loop when first locked file is found.
Bugs:


After building your list, you throw it away without printing anything (and if not, please supply all your code)


Minor:


pathlib >>> os. It leads to much better readable code, and less boilerplate.
is_locked=list() should be: is_locked = [] Note spaces and the literal.
pf.close() isn't a reliable statement. Instead, consider using something like with open(full_filename) as pf: pass
"path/to/directory" is a magic variable. Make it a global constant instead.
Use a if __name__ == "__main__": guard. Always.


Are you going to manually unlock all the files?

If not, you can just break after the first error and inform the user.