Move all files to parent directory

ParentPath="C:\Users\abc\Desktop\a"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(ParentPath)
Set colSubfolders = objFolder.Subfolders

For Each objSubfolder in colSubfolders

'Wscript.Echo objSubfolder.Name
FolderLoop(ParentPath & "\" & objSubfolder.Name)

Next

Set colSubfolders = Nothing
Set objFolder = Nothing
Set objFSO = Nothing

Function FolderLoop(Path)
Set objFolder1 = objFSO.GetFolder(Path)
Set colSubfolders1 = objFolder1.Subfolders

Set colFiles = objFolder1.Files
For Each objFile in colFiles
'Wscript.Echo Path & "\" & objFile.Name
objFSO.MoveFile Path & "\" & objFile.Name, ParentPath & "\"
Next


For Each objSubfolder1 in colSubfolders1
Wscript.Echo objSubfolder1.Name
FolderLoop(Path & "\" & objSubfolder1.Name)
Next

objFSO.DeleteFolder(Path)
Set colSubfolders1 = Nothing
Set objFolder1 = Nothing
End Function


Move all files to parent directory from the subfolder and delete the subfolder (include recursive subfolder)

Published link

Comments

Popular posts from this blog

Openshift cert-manager integrate with ACME IdM on RHEL (Technical Preview)

TimeSync using ansible and rhel-system-roles.timesync

Remove HPE iLO license