Can I merge files and move in a command?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Can I merge files and move in a command?

#1 Post by tweacle » 11 Apr 2018 08:37

Hi everyone apologies if ive posted in wrong forum but think DOS commands is what I need.

I have a folder of which is C:/Downloads of which has files and folders in it.

What im trying to do is if possible when I click on the shortcut icon on the desktop i need to create a new folder within C:/Downloads and then move all the files into that folder. There will be other folders within the folder C:/Downloads already but I just need the individual files to be moved. Once it has moved the files I need a message box or something to pop up asking me to name what the folder is going to be called and then name it.

Any ideas if this is possible.

Thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can I merge files and move in a command?

#2 Post by aGerman » 11 Apr 2018 14:55

There is no such thing like a message box in Batch. To help out I'll offer you a VBScript code (save with file extension .vbs)

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&
Steffen

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

Re: Can I merge files and move in a command?

#3 Post by tweacle » 12 Apr 2018 04:08

Seffen

A BIG BIG Thanks.

You are a legend and saved me loads of work doing that.

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

Re: Can I merge files and move in a command?

#4 Post by tweacle » 12 Apr 2018 04:30

I forgot one thing sorry !!

The script above works perfectly but there one thing I missed off. What im trying to do is if poss when folder created and files moved I need the folder C:/Downloads to re open to show the folders and launch 7 zip file manager so I can ZIP and password protect file.

If youre not able to launch 7 zip file manager thats fine as long as I can get it to reopen C:/Downloads.

Thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can I merge files and move in a command?

#5 Post by aGerman » 12 Apr 2018 05:00

Just add this line at the end of the script.

Code: Select all

objWShell.Run "explorer.exe /select,""" & objFSO.BuildPath(strDLFolder, strNewFolder) & """"
Steffen

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

Re: Can I merge files and move in a command?

#6 Post by tweacle » 12 Apr 2018 08:45

Steffen

A big big thanks once again

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

Re: Can I merge files and move in a command?

#7 Post by tweacle » 31 May 2018 03:32

Is there anyway I can add to command below...

What it does at present is exactly what I want it to do but im trying to amend the end so that once folder created and files moved I want to have a message box or something pop up asking me if to save to section A or B and then I click on selection it moves the folder and opens it in the new section and once opened the window at the end pop up as this text

Code: Select all

objWShell.Popup "ALL FILES MOVED NOW 7ZIP AND PASSWORD PROTECT FOLDER", 0, "Done", vbInformation Or vbSystemModal Or &h00040000&
[/code]

I.E created the folder and then click on selection "A" and folder then moves to C:\DOWNLOADS\SECTIONA and then opens it and pops with with the message "ALL FILES MOVED NOW 7ZIP AND PASSWORD PROTECT FOLDER"
or if I select "B" I need it moving to C:\DOWNLOADS\SECTIONB and then opens it and pops with with the message "ALL FILES MOVED NOW 7ZIP AND PASSWORD PROTECT FOLDER"

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&

Is this possible.

Thanks

Post Reply