Robocopy: A simple way to copy only the word / excel lock files and their folders

Question:

How can I use Robocopy to copy only the folders and files that start with ~$ from a large directory?

I received a directory from a client that contains many word / excel lock files (e.g. ~$FILENAME.docx, ~$FILENAME.xlsx) along with other files and folders. I want to send back a copy of the directory that only includes the lock files and their corresponding folders, and excludes any other files or folders that do not contain ~$. This way, I can ask the client to resend the actual files instead of the lock files. How can I achieve this using Robocopy?

Answer:

How to use Robocopy to copy only the lock files from a directory

Robocopy is a powerful command-line tool that can copy files and folders between different locations, with various options and filters. In this article, we will show you how to use Robocopy to copy only the folders and files that start with ~$ from a large directory, and exclude any other files or folders that do not contain ~$.

Sometimes, you may receive a directory from a client or a colleague that contains many word / excel lock files (e.g. ~$FILENAME.docx, ~$FILENAME.xlsx) along with other files and folders. These lock files are temporary files that are created when someone opens a word or excel document, and they are usually hidden and deleted when the document is closed. However, sometimes they may remain in the directory due to various reasons, such as network issues, improper shutdown, or corrupted files.

These lock files are not useful for you, and they may prevent you from opening the actual files that you need. Therefore, you may want to send back a copy of the directory that only includes the lock files and their corresponding folders, and exclude any other files or folders that do not contain ~$. This way, you can ask the client or the colleague to resend the actual files instead of the lock files, and avoid any confusion or duplication.

How to use Robocopy to copy only the lock files?

To use Robocopy to copy only the lock files from a directory, you need to specify the source and destination paths, and use the /XF and /XD options to exclude any files or folders that do not match the ~$ pattern. For example, if the source directory is C:\Source and the destination directory is D:\Destination, you can use the following command:

“`cmd

robocopy C:\Source D:\Destination /XF *.* /XD * /S /E /R:0 /W:0 /MT:32 /L

“`

Let’s break down the command and explain what each option does:

  • `/XF *.*` excludes any files that do not have a ~$ in their name. The *.* means any file name and any extension, so this option will exclude all files except the lock files.
  • `/XD *` excludes any folders that do not have a ~$ in their name. The * means any folder name, so this option will exclude all folders except the ones that contain lock files.
  • `/S` copies subdirectories, but not empty ones.
  • `/E` copies subdirectories, including empty ones.
  • `/R:0` specifies the number of retries on failed copies. 0 means no retries, so this option will skip any files or folders that cannot be copied due to errors or permissions.
  • `/W:0` specifies the wait time between retries, in seconds. 0 means no wait, so this option will speed up the copying process.
  • `/MT:32` specifies the number of threads to use for copying. 32 means 32 threads, which is the maximum number allowed by Robocopy. This option will improve the performance and efficiency of the copying process.
  • `/L` lists the files and folders that would be copied, without actually copying them. This option is useful for testing and verifying the command before executing it.
  • Note that the order of the options does not matter, as long as they are after the source and destination paths. Also, note that the command is case-insensitive, so you can use upper or lower case letters for the options.

    How to verify the results?

    After running the command, you can check the output on the screen or in a log file, if you specified one using the /LOG option. The output will show you the summary of the copying process, such as the number of files and folders copied, skipped, or failed, and the total size and time of the operation. You can also compare the source and destination directories using a file explorer or a file comparison tool, and see that only the lock files and their corresponding folders are copied.

    Conclusion

    In

this article, we showed you how to use Robocopy to copy only the folders and files that start with ~$ from a large directory, and exclude any other files or folders that do not contain ~$. This can be useful when you receive a directory that contains many word / excel lock files, and you want to ask the sender to resend the actual files instead of the lock files. We hope you found this article helpful and informative. If you have any questions or feedback, please leave a comment below. Thank you for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *

Privacy Terms Contacts About Us