Windows 10 delete reparse points in (sub)directories

Windows 10 delete reparse points in (sub)directories

Recently Windows 10 went through the fall creator’s update without my permission, I found out that I can no longer access my onedrive folder while I’m booted into linux. To clarify, the folder does not shows up in gui but does shows up red when using ls command in the directory. Through many frustrations and this post here, I realize it’s something the update did that created reparse points on everything in my onedrive folder. And from the same place I found the command below to delete reparse points, one at a time. It wasn’t enough to solve the problem since I have more than 100 folders in my onedrive.

fsutil reparsepoint delete "C:\Path\To\OneDrive\Folder"

Since it only happened to my folders/files in onedrive, first thing I tried is move everything out of it to a separate location and create symlink back in onedrive so I can keep them updated in the cloud. Unfortunately, that did not fix the problem, those reparse point lives and still denying me access to my own files. Frustrated, I started using fsutil command to delete the reparse points one by one. Soon I realized it wasn’t an acceptable solution since it’ll take hours. So frustrated and angry at Microsoft, I created a python script to apply the command above to everything in the directory.

First through I need to get a list of all the files/directory/subdirectory. I found this really neat one line command in stackoverflow post here.

[val for sublist in [[os.path.join(i[0], j) for j in i[2]] for i in os.walk('./')] for val in sublist]

Do note that you need to replace ‘./’ to whatever path string you desires.

However, this one line command only gather a list of files, without directory or subdirectories.

With help from this post, it is this command here that really does the job of gathering everything.

l = []
for root, directories, filenames in os.walk('./'):
    for directory in directories:
        l.append(os.path.join(root, directory))
    for filename in filenames:
        l.append(os.path.join(root, filename))

Now that I have a list of all the files, directories and subdirectories, I can use a for loop to run the fsutil command on each and every one of them. Since my computer is fast enough and I’m lazy, I’m not going to shy away from launching too many command prompt and included a line to start command prompt so that I can verify it works.

Here’s the final script I whipped up to solve the problem, it will launch a cmd window for every single thing in the selected folder, so anyone who found and intend to use it beware of its danger:

import os

l = []
for root, directories, filenames in os.walk('E:\Personal'):
    for directory in directories:
        l.append(os.path.join(root, directory))
    for filename in filenames:
        l.append(os.path.join(root, filename))

for a in l:
    args = 'fsutil reparsepoint delete "' + a + '"'
    start = "start cmd /k " + '"' + args + '"'
    os.popen(start)

 

Update 31/08/2018: Got replies below pointed out my mistake of including the start line at the end to run the command with cmd. The idea behind it was to running the command in a terminal so that I can verify that it works, but it was clearly unwise to include it in a for loop which would summons a cmd for every single file/folder you have, potentially crashing the computer. Taking that out and run os.popen(args) instead would be cleaner. Here’s the modified for loop.

for a in l:
    args = 'fsutil reparsepoint delete "' + a + '"'
    os.popen(args)

Update 05/02/2019: Another very helpful reply! I should’ve mentioned that the cause to the reparse points are the “Files on Demand” feature in OneDrive. Turning it off should no longer create reparse points on your new files and folder. Unfortunately, Windows does not delete the already exist reparse points. According to empty_other’s reply below, launch powershell, navigate to OneDrive folder and run the command below should fix the problem. Much more cleaner than my python solution!

Get-ChildItem -Recurse -Attributes Reparsepoint | % { $n = $_.FullName.Trim(“\”); fsutil reparsepoint delete “$n” }

5 thoughts on “Windows 10 delete reparse points in (sub)directories

  1. thanks for the inspiration!
    but: delete the entire start line, call os.popen(args)
    there’s no need to start thousands of cmds and kill the system

    1. You’re right there’s no need for the start line, I did not think of that while I was writing this up. Thanks for letting me know!

  2. Had the same issue recently, with the result that I couldn’t delete my OneDrive folders. Seems Windows can’t delete reparse point folders.

    Turn off “FIles on Demand” option should prevent new folders and files from being created as reparse points. To fix the old files use powershell to navigate to your OneDrive folder, then run this:

    Get-ChildItem -Recurse -Attributes Reparsepoint | % { $n = $_.FullName.Trim(“\”); fsutil reparsepoint delete “$n” }

    Does the same thing as your Python script, I believe. But doesn’t spawn all those cmds.

    1. Yeap forgot to mention in this post, discovered “Files on Demand” is the cause and I’ve had it disabled ever since. Brilliant! I’ll add your solution to the post as well, hope I was smart enough to figure that out when I had the issue. Spawning the cmds weren’t necessary and it was a method for me to verify that it works while I was testing the script, I left it in while I execute it on all the files/folders, which was certainly unwise.

  3. Trying the last command in my one drive folder

    Get-ChildItem -Recurse -Attributes Reparsepoint | % { $n = $_.FullName.Trim(“\”); fsutil reparsepoint delete “$n” }

    I get the error:

    Error: The tag present in the reparse point buffer is invalid.

Leave a Reply

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