Discussion, questions and support.
-
vrod5454
- Posts: 20
- Joined: Apr 18th, ’18, 02:13
Post
by vrod5454 » Jun 3rd, ’22, 02:01
Hi,
I have a a folder structure that I would like to copy to a destination folder by using a START MENU (Middle click) and selecting my "COPY FOLDER STRUCTURE" FastKeys Automation command . The code below works great, but the DestinationFolder path is hard coded ""C:\Users\ME\Desktop\DESTINATION_FOLDER\".
How can I get the path of current directory where I am middle clicking to be the DestinationFolder - so the folder structure is copied there?
Thanks for your help!
Code: Select all
ErrorCount := CopyFilesAndFolders("C:\Users\ME\Desktop\SOURCE_FOLDER\*.*", "C:\Users\ME\Desktop\DESTINATION_FOLDER\")
if (ErrorCount != 0)
MsgBox %ErrorCount% files/folders could not be copied.
CopyFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = false)
; Copies all files and folders matching SourcePattern into the folder named DestinationFolder and
; returns the number of files/folders that could not be copied.
{
; First copy all the files (but not the folders):
FileCopy, %SourcePattern%, %DestinationFolder%, %DoOverwrite%
ErrorCount := ErrorLevel
; Now copy all the folders:
Loop, %SourcePattern%, 2 ; 2 means "retrieve folders only".
{
FileCopyDir, %A_LoopFileFullPath%, %DestinationFolder%\%A_LoopFileName%, %DoOverwrite%
ErrorCount += ErrorLevel
if ErrorLevel ; Report each problem folder by name.
MsgBox Could not copy %A_LoopFileFullPath% into %DestinationFolder%.
}
return ErrorCount
}
-
Tom
- Posts: 796
- Joined: Nov 24th, ’15, 23:39
Post
by Tom » Jun 4th, ’22, 09:54
Add this to the beginning of the script to get the current opened folder in Windows Explorer:
Code: Select all
for w in ComObjCreate("Shell.Application").Windows
DestinationFolder := w.Document.Folder.Self.Path
-
vrod5454
- Posts: 20
- Joined: Apr 18th, ’18, 02:13
Post
by vrod5454 » Jul 8th, ’22, 23:57
Hi Tom,
I added the code to the beginning of my script and adjusted CopyFilesAndFolders to use %DestinationFolder% and not the fixed path "C:\Users\ME\Desktop\DESTINATION_FOLDER\".
Problem is I am getting the following error:
"Error0x8001010D - An outgoing call cannot be made since the application is dispatching an input-synchronous call."
Did I use your code incorrectly? Below is the code I am using:
Code: Select all
for w in ComObjCreate("Shell.Application").Windows
DestinationFolder := w.Document.Folder.Self.Path
ErrorCount := CopyFilesAndFolders("C:\Users\ME\Desktop\SOURCE_FOLDER\*.*", %DestinationFolder%)
if (ErrorCount != 0)
MsgBox %ErrorCount% files/folders could not be copied.
CopyFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = false)
; Copies all files and folders matching SourcePattern into the folder named DestinationFolder and
; returns the number of files/folders that could not be copied.
{
; First copy all the files (but not the folders):
FileCopy, %SourcePattern%, %DestinationFolder%, %DoOverwrite%
ErrorCount := ErrorLevel
; Now copy all the folders:
Loop, %SourcePattern%, 2 ; 2 means "retrieve folders only".
{
FileCopyDir, %A_LoopFileFullPath%, %DestinationFolder%\%A_LoopFileName%, %DoOverwrite%
ErrorCount += ErrorLevel
if ErrorLevel ; Report each problem folder by name.
MsgBox Could not copy %A_LoopFileFullPath% into %DestinationFolder%.
}
return ErrorCount
}