Page 1 of 1

How to not merge folders already created

Posted: 03 Jun 2018 04:52
by tweacle
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?

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) & """"

Re: How to not merge folders already created

Posted: 03 Jun 2018 05:36
by SIMMS7400
This is a batch forum - not VB. Your ask can be coded in 3 lines with batch, is there a reason you're not using a match method?

Re: How to not merge folders already created

Posted: 03 Jun 2018 05:42
by tweacle
:oops: oopppsss. Sorry no there no reason why I cant have it as a batch Ain’t got a clue on how to write one tho ... :shock:

Re: How to not merge folders already created

Posted: 03 Jun 2018 09:00
by MarioZac
Here you ask "how to merge files", and now you ask "how to NOT merge". Do you know exactly what you need? It looks like you're trying to learn basic coding skills by asking others to write script examples for you. Did you try bugging Google instead? Best thing is attempting to code yourself and posting your own errors. At least you'll learn something in the process.

Re: How to not merge folders already created

Posted: 04 Jun 2018 05:05
by pieh-ejdsch
Hello tweacle,
This want help you.

Code: Select all

Setlocal
PushD C:\Downloads
set "newFolder=newFolderName"
md "%newFolder%"
Move * "%newFolder%"
popD
Phil

Re: How to not merge folders already created

Posted: 04 Jun 2018 08:04
by MarioZac
Or modify the above snippet to prompt for new folder name:

Code: Select all

set /p "newFolderName=Enter new destination folder name > "