Hi,
I made this code with the assistance of Ai, to move selected files and folders in the current folder to a new custom folder by input box
it works fine for moving single file or folder, but when selecting multiple file and folder, an input boxes appear according to the number of the selected files and folder, if I selected 2 files or folders ----> two input boxes appear, 50 files or folders ----> 50 input boxes and so on. So how to make input box appear only once to type the desired folder name and completing the moving process. Furthermore, if anyone have another code to do the same function, please provided it, as it will be so helpful for me with special thanks.
I made this code with the assistance of Ai, to move selected files and folders in the current folder to a new custom folder by input box
Code:
Dim objFSO, objShell, destinationFolder, currentFolder, newFolderName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
' Get the current folder (where the script is executed)
currentFolder = objShell.CurrentDirectory
' Prompt user for new folder name
newFolderName = InputBox("Enter the name of the new folder:", "Create New Folder")
' Exit if no input is provided
If Trim(newFolderName) = "" Then
WScript.Quit
End If
' Build the path for the new folder
destinationFolder = objFSO.BuildPath(currentFolder, newFolderName)
' Create the folder if it doesn't already exist
If Not objFSO.FolderExists(destinationFolder) Then
objFSO.CreateFolder(destinationFolder)
End If
' Loop through the selected items passed as arguments
For Each item In WScript.Arguments
If objFSO.FolderExists(item) Then
' If the item is a folder, move it
objFSO.MoveFolder item, destinationFolder & "\"
ElseIf objFSO.FileExists(item) Then
' If the item is a file, move it
objFSO.MoveFile item, destinationFolder & "\"
End If
Next
' Notify the user
MsgBox "Files and folders moved successfully to " & destinationFolder, vbInformation, "Operation Completed"