Reputation: 2731
Besides trying the operation and catching the exception, is there a method to determine if a file can be moved or copied?
Upvotes: 4
Views: 2023
Reputation: 347406
There is no way to know if a file move or copy will guaranteed succeed or not.
But you can check quite a few things to see if it will fail:
More on file locking:
Please see my answer here for much more information on file locking & permissions in linux.
Please see my answer here for much more information on file locking & permissions in Windows.
Upvotes: 6
Reputation: 4956
If the file can be read, it can be moved or copied. Are you asking how you can check if the move or copy will succeed?
Upvotes: -1
Reputation: 28499
In general, see if the File exists and that the current user has permission to read the file (or delete the file for move) and has the appropriate permission for the destination directory. As well, for copy, you should check that there is available disk space. Of course, before all that, make sure the original file and destination directory even exist.
Of course, this does not gurantee the operation will succeed. Many things can happen. Even the permissions for the file can change between the time you check and the time you do the operation.
Upvotes: 0