Solved dialog box help to move files

June 1, 2018 at 08:42:07
Specs: Windows 7
HI

Donno if I can do this or not.

Im looking to create what I believe to be a dialog box of which will ask me a question and the option of YES/NO but aint got a clue where to start

What im trying to do is if I push "YES" I need folder moving from C:\DOCUMENTS to C:\DOCUMENTS\A and if i push "NO" I need it moving to C:\DOCUMENTS\B.

The other thing is I need it to run after a .VBS script that I already have of which is below.

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


See More: dialog box help to move files

Reply ↓  Report •

#1
June 1, 2018 at 20:55:54
Clarification, does this sound close to what you intend?
Move one folder, (folder-name not specified) rooted in c:\documents to one of two sub-folders "A" or "B", based on dialogue response, then access that folder using explorer.

When you say "folder", I read "subdirectory". Do you mean "folder" or "FILE"? That distinction is very important in communicating your intent.

VBscript is kind of overkill for what you want (as I interpret it), but it will of course work,
with modifications to the posted code.


Reply ↓  Report •

#2
June 1, 2018 at 23:18:06
Yup exactly what I need.

I think possibly sub directory. It’s a folder of which has another folder with data within it and that the folder I need to move ..

It don’t have to have a vb script as long as it does all what I put in already too and can click on icon on desktop to run it

message edited by GDB


Reply ↓  Report •

#3
June 2, 2018 at 20:55:01
✔ Best Answer
Ok, fair enough. Still lacking some specs, but here's a prototype:
@echo off & setlocal
:: this is where the simple one-liner vbs will be created - could be anywhere
:: but make sure the location exists...
set vbs=\vbs
:: create the vbs-msgbox gui interface
if exist %vbs%\ab.vbs goto :safety
>%vbs%\ab.vbs echo wscript.echo msgbox("Yes=A, No=B",vbyesnocancel)
:: execute the simple box and capture: 6=Yes, 7=No else ignore/abort
:safety
for /f "tokens=1" %%a in ('cscript %vbs%\ab.vbs') do set ab=%%a
set dest=
set msg=Abort
if %ab% equ 6 set dest=A
if %ab% equ 7 set dest=B

:xit
:: timeout is length of time for results-msg to display
set timeout=5
:: send results to GUI-msg box
if defined dest set msg=moving %dest%
msg %username% /time:%timeout% %msg%
if not defined dest goto :eof
:: do the moving here: disabled for my testing.
rem move something to c:\documents\%dest%
rem start c:\documents\%dest%


Reply ↓  Report •

Related Solutions

#4
June 3, 2018 at 11:13:27
Many thanks nbrane but I have come to the conclusion that Im confusing myself and also everyone else.


Ive tried looking on google but cant find but I can amend the txt below so that when I create a subfolder and it moves files into it I DO NOT want the subfolders that are already in there moved into the new one.

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


Reply ↓  Report •

Ask Question