At this post
viewtopic.php?f=76&t=60237 the code is working fine for files selected one by one
Any one knows how to adapt it for working for more than on selected files?
Script to copy selected file names / create folder / copy file to folder Topic is solved
Re: Script to copy selected file names / create folder / copy file to folder
Press F1
Code: Select all
Gui, -MinimizeBox
Gui, Add, Edit, w400 vCopy2 Center, %A_ScriptDir%\TestFolder
Gui, Show,, CopyFiles
Return
GuiClose:
ExitApp
F1::
Gui, Submit, NoHide
If (!Copy2) {
MsgBox, 16, NoDest, No Destination!
} Else {
FileCreateDir, %Copy2%
If (ErrorLevel) {
MsgBox, 16, FolderCreationError, Code: %ErrorLevel%
} Else {
If (!List := Explorer_GetSelection()) {
MsgBox, 64, Info, No selection
} Else {
Loop, Parse, % List, `n, `r
{
If InStr(FileExist(A_LoopField), "D") {
MsgBox, 64, Info, %A_LoopField%`n`nfolders are not included
} Else {
FileCopy, % A_LoopField, % Copy2
If (ErrorLevel) {
MsgBox, 16, CopyingError, Code: %ErrorLevel%
}
}
}
}
}
}
Return
Explorer_GetSelection() { ; https://www.autohotkey.com/boards/viewtopic.php?p=255256#p255256
WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
if !(winClass ~="Progman|WorkerW|(Cabinet|Explore)WClass")
Return
shellWindows := ComObjCreate("Shell.Application").Windows
if (winClass ~= "Progman|WorkerW")
shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP := 8, 0, SWFO_NEEDDISPATCH := 1).Document
else {
for window in shellWindows
if (hWnd = window.HWND) && (shellFolderView := window.Document)
break
}
for item in shellFolderView.SelectedItems
result .= (result = "" ? "" : "`n") . item.Path
if !result
result := shellFolderView.Folder.Self.Path
Return result
}
Re: Script to copy selected file names / create folder / copy file to folder
Hi,
thank you for the code.
I am not sure how to use it
I was expected something like this:
Run script
Press the Hotkey ( e.g F1::)
Select 2 or more files in a folder
A folder with the same name of first selected file is created.
This first file is moved inside the folder (named as the first file)
A folder with the same name of second selected file is created.
The second file is moved inside the folder (named as the second file)
and so on with the rest selected files
The script at viewtopic.php?f=76&t=60237
is doing what i need , but i have to select every file one by one
Thank you!
thank you for the code.
I am not sure how to use it
I was expected something like this:
Run script
Press the Hotkey ( e.g F1::)
Select 2 or more files in a folder
A folder with the same name of first selected file is created.
This first file is moved inside the folder (named as the first file)
A folder with the same name of second selected file is created.
The second file is moved inside the folder (named as the second file)
and so on with the rest selected files
The script at viewtopic.php?f=76&t=60237
is doing what i need , but i have to select every file one by one
Thank you!
Re: Script to copy selected file names / create folder / copy file to folder Topic is solved
Well Well try this
Edit: I modified it a little.
Code: Select all
Gui, -MinimizeBox
Gui, Add, Text, w400 r6 Center Border, % "`n1 - Select the files."
. "`n2 - Press F1 to apply."
. "`n3 - Wait for a message saying it is done."
. "`n4 - Done."
Gui, Show,, CopyFiles
Return
Esc::
GuiClose:
ExitApp
F1::
Cnt := 0
Loop, Parse, % Explorer_GetSelection(), `n, `r
{
If InStr(FileExist(A_LoopField), "D") {
MsgBox, 64, Info, %A_LoopField%`n`nfolders are not included
} Else {
SplitPath, % A_LoopField, OutName, OutDir,, OutNameNoExt
ToolTip, Processing %OutName%
FileCreateDir, % OutDir "\" OutNameNoExt
If (ErrorLevel) {
MsgBox, 16, FolderCreationError, Code: %ErrorLevel%
} Else {
FileCopy, % A_LoopField, % OutDir "\" OutNameNoExt
If (ErrorLevel) {
MsgBox, 16, CopyingError, Code: %ErrorLevel%
}
(!Cnt) ? Cnt := 1
}
}
}
ToolTip
If (Cnt)
MsgBox, 64, Done, Done.
Return
Explorer_GetSelection() { ; https://www.autohotkey.com/boards/viewtopic.php?p=255256#p255256
ToolTip, Getting selection %OutName%
WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
if !(winClass ~="Progman|WorkerW|(Cabinet|Explore)WClass")
Return
shellWindows := ComObjCreate("Shell.Application").Windows
if (winClass ~= "Progman|WorkerW")
shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP := 8, 0, SWFO_NEEDDISPATCH := 1).Document
else {
for window in shellWindows
if (hWnd = window.HWND) && (shellFolderView := window.Document)
break
}
for item in shellFolderView.SelectedItems
result .= (result = "" ? "" : "`n") . item.Path
Return result
}
Re: Script to copy selected file names / create folder / copy file to folder
Hi, excellent !!
The gui generated how to guide is helpful, and the rest code works as expected!
(Changing , FileCopy to FileMove at line 26 is better for my needs)
Thank you!!
The gui generated how to guide is helpful, and the rest code works as expected!
(Changing , FileCopy to FileMove at line 26 is better for my needs)
Thank you!!
Re: Script to copy selected file names / create folder / copy file to folder
Gud to know! , have fun
You can also add progress bar if you have a lot of files to process.
You can also add progress bar if you have a lot of files to process.