Miscellaneous‎ > ‎

Onedrive: how to rename folders to remove # from folder name

Microsoft Onedrive won't synch any folders or files that contain a "#" in the name.

So you have to rename folders to remove the # in the name.   If you have a lot of folders, that is a real pane.

This vbscript will systematically remove the # from all folders under your OneDrive primary folder location:


BEGIN SCRIPT:


Set fso = CreateObject("Scripting.FileSystemObject")
Set folder=fso.GetFolder("C:\Users\mkplumbing\OneDrive - MK Plumbing Company, Inc\Shared with Everyone")

'Subfolder level 1
For Each Subfolder in Folder.SubFolders
Set folder2=fso.GetFolder(Subfolder)
For Each Subfolder2 in Folder2.SubFolders
pos = InStr(folder2.Name, "#")
if pos >0 then
FSo.MoveFolder subfolder2, replace(subfolder2,"#","")
end if
Next
Next

'Subfolder level 2
For Each Subfolder in Folder.SubFolders
Set folder2=fso.GetFolder(Subfolder)
For Each Subfolder2 in Folder2.SubFolders
Set folder3=fso.GetFolder(Subfolder2)
For Each Subfolder3 in Folder3.SubFolders
pos = InStr(folder3.Name, "#")
if pos>0 then
FSo.MoveFolder subfolder3, replace(subfolder3,"#","")
end if
Next
Next
Next

'Subfolder level 3
For Each Subfolder in Folder.SubFolders
Set folder2=fso.GetFolder(Subfolder)
For Each Subfolder2 in Folder2.SubFolders
Set folder3=fso.GetFolder(Subfolder2)
For Each Subfolder3 in Folder3.SubFolders
Set folder4=fso.GetFolder(Subfolder3)
For Each Subfolder4 in Folder4.SubFolders
pos = InStr(folder4.Name, "#")
if pos>0 then
FSo.MoveFolder subfolder4, replace(subfolder4,"#","")
end if
Next
Next
Next
Next

'Subfolder level 4 
For Each Subfolder in Folder.SubFolders
Set folder2=fso.GetFolder(Subfolder)
For Each Subfolder2 in Folder2.SubFolders
Set folder3=fso.GetFolder(Subfolder2)
For Each Subfolder3 in Folder3.SubFolders
Set folder4=fso.GetFolder(Subfolder3)
For Each Subfolder4 in Folder4.SubFolders
Set folder5=fso.GetFolder(Subfolder4)
For Each Subfolder5 in Folder5.SubFolders
pos = InStr(folder5.Name, "#")
if pos>0 then
FSo.MoveFolder subfolder5, replace(subfolder5,"#","")
end if
Next
Next
Next
Next
Next

'Subfolder level 5
For Each Subfolder in Folder.SubFolders
Set folder2=fso.GetFolder(Subfolder)
For Each Subfolder2 in Folder2.SubFolders
Set folder3=fso.GetFolder(Subfolder2)
For Each Subfolder3 in Folder3.SubFolders
Set folder4=fso.GetFolder(Subfolder3)
For Each Subfolder4 in Folder4.SubFolders
Set folder5=fso.GetFolder(Subfolder4)
For Each Subfolder5 in Folder5.SubFolders
Set folder6=fso.GetFolder(Subfolder5)
For each subfolder6 in FOlder6.subfolders
pos = InStr(folder6.Name, "#")
if pos>0 then
FSo.MoveFolder subfolder6, replace(subfolder6,"#","")
end if
Next
Next
Next
Next
Next
Next




msgbox "done"
Comments