How to not merge folders already created

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

How to not merge folders already created

#1 Post by tweacle » 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?

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

SIMMS7400
Posts: 539
Joined: 07 Jan 2016 07:47

Re: How to not merge folders already created

#2 Post by SIMMS7400 » 03 Jun 2018 05:36

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?

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: How to not merge folders already created

#3 Post by tweacle » 03 Jun 2018 05:42

: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:

MarioZac
Posts: 38
Joined: 16 May 2018 00:12

Re: How to not merge folders already created

#4 Post by MarioZac » 03 Jun 2018 09:00

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.

pieh-ejdsch
Posts: 239
Joined: 04 Mar 2014 11:14
Location: germany

Re: How to not merge folders already created

#5 Post by pieh-ejdsch » 04 Jun 2018 05:05

Hello tweacle,
This want help you.

Code: Select all

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

MarioZac
Posts: 38
Joined: 16 May 2018 00:12

Re: How to not merge folders already created

#6 Post by MarioZac » 04 Jun 2018 08:04

Or modify the above snippet to prompt for new folder name:

Code: Select all

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

Post Reply