Created
February 4, 2017 04:01
-
-
Save privatmamtora/850de8b03f5117af68753c0868e00383 to your computer and use it in GitHub Desktop.
Script that will mode all files to the root of the directory provided (Flatten deep folders)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if WScript.Arguments.Count = 0 then | |
| WScript.Echo "Missing parameters" | |
| end if | |
| Sub Pause(strPause) | |
| WScript.Echo (strPause) | |
| End Sub | |
| Function MoveOrCopyFile(Source, Destination, FileName) | |
| If objFSO.FileExists(Destination & "\" & FileName) Then | |
| suffix = 97 | |
| Do While objFSO.FileExists(Destination & "\" & objFSO.GetBaseName(FileName) & Chr(suffix) & "." & objFSO.GetExtensionName(FileName)) | |
| suffix = suffix + 1 | |
| If suffix > 122 Then | |
| suffix = 65 | |
| End If | |
| Loop | |
| src = Source & "\" & FileName | |
| dest = Destination & "\" & objFSO.GetBaseName(FileName) & Chr(suffix) & "." & objFSO.GetExtensionName(FileName) | |
| Pause (dest) | |
| objFSO.CopyFile src, dest | |
| Else | |
| objFSO.MoveFile Source & "\" & FileName, Destination & "\" | |
| End If | |
| End Function | |
| Function FolderLoop(Path, Folder) | |
| Set objFolder1 = objFSO.GetFolder(Folder) | |
| Set colSubfolders1 = objFolder1.Subfolders | |
| Set colFiles = objFolder1.Files | |
| For Each objFile in colFiles | |
| MoveOrCopyFile Folder, Path, objFile.Name | |
| Next | |
| For Each objSubfolder1 in colSubfolders1 | |
| FolderLoop Path, Folder & "\" & objSubfolder1.Name | |
| Next | |
| objFSO.DeleteFolder(Folder) | |
| Set colFiles = Nothing | |
| Set colSubfolders1 = Nothing | |
| Set objFolder1 = Nothing | |
| End Function | |
| Set objFSO = CreateObject("Scripting.FileSystemObject") | |
| Set folders = Wscript.Arguments | |
| For Each path In folders | |
| Set objFolder = objFSO.GetFolder(path) | |
| Set colSubfolders = objFolder.Subfolders | |
| For Each objSubfolder in colSubfolders | |
| FolderLoop path, path & "\" & objSubfolder.Name | |
| Next | |
| Set colSubfolders = Nothing | |
| Set objFolder = Nothing | |
| Next | |
| Set folders = Nothing | |
| Set objFSO = Nothing | |
| Pause("Files moved up completed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment