Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selfmoving ?
#1
hy gintaras

im trying to make my exefile moving itself to a predefined folder on desktop if it is not already saved in that folder.

The code i made works good - when i open the exefile on my C drive it moves itself to the folder on desktop but when open it for example from my D drive or usb stick it just copies it self instead of moving maybe u can tell me what im doing wrong!?
Or is there a better way to do this?


Function Dialog4
Code:
Copy      Help
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("Dialog4" &Dialog4)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030109 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,exemove
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


Function exemove
Code:
Copy      Help
int hwnd = win("Form" "#32770")
int xfind
str myfolder = "$desktop$\My Files"
str currentsaved

currentsaved.getwinexe(hwnd 1)
xfind = find(currentsaved "My Files")
if(xfind = -1)
,mkdir myfolder
,1
,ren currentsaved myfolder
,mes "File moved to folder ''My Files'' on desktop. "


best regards
#2
If does not delete the source file, delete it explicitly.

cop currentsaved myfolder
del- currentsaved
#3
Omg makes me look stupid ! just did not think about deleting .. thanks

One more question

if the file is already saved in that folder and i open it again from a different place - How can i keep the replace/overwrite dialog away ?

thanks alot
#4
It doesnt delete the source file ! i think because its running ...
#5
Yes. Cannot delete self.
#6
Quote:if the file is already saved in that folder and i open it again from a different place - How can i keep the replace/overwrite dialog away ?

cop- currentsaved myfolder
#7
so if i understand it right del- currentsaved does actually nothing coz the file cant delete itself while its running ...!?

why to put it in then?

Just wodering if u have got an other idea or if that is all help ill get ..

best regards
#8
Use other exe to move your exe.
#9
makes no sense in my eyes

ty
#10
That other exe could be the same exe copied to $temp$ folder...
#11
never did something like that ,sounds complicated...im not that good on working new things fast out, so i probably quit that feature.

thanks alot
#12
Function exemove
Code:
Copy      Help
;note: the main function of the exe must be function, not macro.
;note: this function should be called somewhere at the beginning of the main function, not on WM_INITDIALOG.


str myExe=ExeFullPath
;out myExe
str correctFolder.expandpath("$desktop$\My Files")
str correctExe.from(correctFolder "\" _s.getfilename(myExe 1))

if myExe~correctExe ;;I am in correct folder
,;what is my command line?
,str s
,if !empty(_command) and findrx(_command "/del ''(.+?)''" 0 1 s 1)
,,;my command line tells me to delete that incorrect exe
,,1 ;;wait until that incorrect exe's process ends
,,del- s; err out "Failed to delete %s" s
,,mes "File moved to folder ''My Files'' on desktop. "
,,end ;;maybe this is not needed
else ;;I am somewhere else
,;copy me to correct folder; cannot move or delete me now, because i'm running.
,mkdir correctFolder
,cop- myExe correctFolder
,;run me from correct folder and pass command line that tells to delete me
,str cmdLine.format("/del ''%s''" myExe)
,run correctExe cmdLine
,;exit
,end

Function ExeFullPath
Code:
Copy      Help
;/
function~

;Returns full path of this exe file.
;If you need only path without filename, instead use special variable _qmdir, or str s.expandpath("$qm$\").


BSTR b.alloc(300)
GetModuleFileNameW(0 b 300)
_s.ansi(b)
_s.dospath(_s 1)
_s.lcase
ret _s
#13
thank you very much i will try it this evening. Some parts looking realy new to me but thanks for explaining it that well !!

best regards
#14
Just want to thank you again - it works perfect


Forum Jump:


Users browsing this thread: 1 Guest(s)