How to not merge folders already created
Posted: 03 Jun 2018 04:52
Hi
The script shown at the bottom creates a subfolder in "C:\Downloads" and moves files that are within it all into it after I named it .
What it is that I already have subfolders within the folder and when im running command its also merging the subfolders that I have alreay created too.
I may be wrong but believe that the line below is causing the issue but donno what to put in. I think that its tellling it for each object in the folder to merge but as mentioned I only need files merged and not the folders. They just need to be left there and do nothing with them.
Am I right and if so what do I need to prevent it from merging subfolders already created.
Any ideas?
The script shown at the bottom creates a subfolder in "C:\Downloads" and moves files that are within it all into it after I named it .
What it is that I already have subfolders within the folder and when im running command its also merging the subfolders that I have alreay created too.
I may be wrong but believe that the line below is causing the issue but donno what to put in. I think that its tellling it for each object in the folder to merge but as mentioned I only need files merged and not the folders. They just need to be left there and do nothing with them.
Am I right and if so what do I need to prevent it from merging subfolders already created.
Any ideas?
Code: Select all
On Error Goto 0
For Each objFile In objDLFolder.Files
objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next
Code: Select all
Option Explicit
Const strDLFolder = "C:\Downloads"
Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")
If Not objFSO.FolderExists(strDLFolder) Then objFSO.CreateFolder(strDLFolder)
objWShell.CurrentDirectory = strDLFolder
Set objDLFolder = objFSO.GetFolder(strDLFolder)
If objDLFolder.Files.Count = 0 Then WScript.Quit
Do
Err.Clear
strNewFolder = InputBox("Folder Name", vbLf & "Enter the name of the folder to be created:")
If strNewFolder = False Then WScript.Quit
On Error Resume Next
objFSO.CreateFolder strNewFolder
Loop While Err.Number <> 0 Or Not objFSO.FolderExists(strNewFolder)
On Error Goto 0
For Each objFile In objDLFolder.Files
objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next
objWShell.Popup "All files moved.", 0, "Done", vbInformation Or vbSystemModal Or &h00040000&
objWShell.Run "explorer.exe /select,""" & objFSO.BuildPath(strDLFolder, strNewFolder) & """"