Posts: 28
Threads: 7
Joined: Apr 2016
06-28-2018, 08:57 PM
Dear Friends
I looking to write a macro that can move selected files from my desktop to specific location.
I came up with the below code.
key Cc
ARRAY(str) a
int i=0
if(GetClipboardFiles(a))
rep a.len
cop a[i] "D:\Files\copied"
del a[i]
i=i+1
OnScreenDisplay "Done !!!"
but is't slow and most of the time is not working without any error message.
any help
Regards
Posts: 1,336
Threads: 61
Joined: Jul 2006
06-28-2018, 10:46 PM
(This post was last modified: 06-28-2018, 11:58 PM by Kevin.)
Why copy and delete when you can just move the file?
try something like this
select the files then run this function
Function
MoveSelectedDesktopFiles
spe 100
ArrangeWindows(0)
key Cc ;; Ctrl+C
ARRAY(str) a
int i
if(GetClipboardFiles(a))
,for i 0 a.len
,,ren+ a[i] "D:\Files\copied"
,OnScreenDisplay "Done !!!"
else
,OnScreenDisplay "No files have been selected !!!"
Posts: 28
Threads: 7
Joined: Apr 2016
@Kevin
Thank you Mr. Kevin. It works pretty well.
but as you know the code will minimize all the opened windows.
I used ArrangeWindows(0) at the end of the code to reverse the effect, but still I have this screen blinking.
Thank you
Posts: 1,336
Threads: 61
Joined: Jul 2006
07-02-2018, 12:54 AM
(This post was last modified: 07-02-2018, 01:13 AM by Kevin.)
Better way no need for ArrangeWindows(0) or GetClipboardFiles
tested on windows 10 and windows7
Function
MoveSelectedDesktopFiles2
spe 100
int hlv=FindDesktopListViewControl
int n=SendMessage(hlv LVM_GETSELECTEDCOUNT 0 0)
str s ss; int item=-1
rep n
,if(GetListViewItemText(hlv item &s 0 2 &item))
,,_s.format("$desktop$\%s[]" s)
,,ss +_s
if n
,ren+ ss "D:\Files\copied"
,OnScreenDisplay "Done !!!"
else
,OnScreenDisplay "No files have been selected !!!"
needs this function as well
Function
FindDesktopListViewControl
;/
function#
;Returns the handle of the SysListView32 control that displays desktop icons.
int w=GetShellWindow
int c=child("" "SysListView32" w 0 "id=1")
if !c
,w=win("" "WorkerW" "" 0 F"threadId={GetWindowThreadProcessId(w 0)}"); if(!w) goto gErr
,c=child("" "SysListView32" w 0 "id=1"); if(!c) goto gErr
ret c
;gErr
end "desktop window not found"
Posts: 1,031
Threads: 246
Joined: Jul 2022
Kewin, Thank you for sharing the code. I have the following questions:
The selected object may be in the following three case
1. Folder
2. File
3. Shortcut
The move operation is only performed when the selected object is a file
How to make a judgment? How to get the file extension? Thank you in advance!