A blog with focus on Windows 10 and cloud <solutions
RSS icon Email icon Home icon

  • Use “attrib” to pin and unpin files and folders for OneDrive On-demand sync in Windows 10

    Posted on September 26th, 2017 By Andreas Stenhall + No comments

    Starting with Windows 10 Fall Creators Update Microsoft has revamped the OneDrive client and is now offering On-Demand synchronization of files. For those of you that remember we had the similar behavior in Windows 8.1 but this was changed for Windows 10.

    There is a huge difference though in how OneDrive On-demand sync works in comparison to how it has been working in Windows 8 and 10 previously. OneDrive is now not just a part of the shell in Windows, it has integration with file system drivers from the kernel. This basically means that we do not face any compatibility issues with applications working with files in OneDrive as there is native Win32 support for accessing files in OneDrive.

    So, with OneDrive On-Demand sync you have three states of the files (more about OneDrive On-Demand sync at the Windows blog). The Icons below marks that the files are downloaded and located on the machine.

    Now, let’s look in the good old command prompt using the dir command to see the status of the above files. Nothing special with this, right?

    But hey, the command attrib has been updated to adhere to the new features of OneDrive On-demand sync.

    To pin a file (i.e. make it always available offline) use the command:

    attrib +p -u Document2.docx

    To unpin a file (i.e. make it available only in the cloud) use the command:

    attrib -p +u Document1.docx

    So, the end result in Windows File Explorer is as below. The cloud icon indicate that the file is only available in the cloud. The green circle with checkmark indicates that the file is always available offline.

    Followed by this view in dir, i.e. note the parenthesis around the file which is available online only.

    Pinning and unpinning multiple files and folders

    To pin or unpin multiple files or folders, use the /s switch. To make all files and folders available recursively:

    attrib +p -u /s

    and to make all files and folders available in the cloud only:

    attrib -p +u /s

    Summary

    To summarize with this new approach and the introduction of OneDrive On-demand sync you will have full application compatibility with OneDrive as well as the possibilities to aid users in controlling their OneDrive files state, or do inventory on it.