What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » copy file

Pages: (3): « First [ 1 ] 2 3 » Last »
copy file
Author: Message:
ainain
New Member
*


Posts: 8
Joined: Jan 2009
O.P. copy file
how to copy and overwrite the file?

for example: c:\a.txt copy to c:\b
05-25-2009 05:20 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: copy file
Javascript code:
CopyFile('c:\\test.log', 'c:\\test.txt');
 
function CopyFile(src, dest) {
    Interop.Call('kernel32', 'CopyFileW', src, dest, false);
}


Javascript code:
RenameFile('c:\\test.log', 'c:\\test.txt');
 
function RenameFile(src, dest) {
    Interop.Call('kernel32', 'MoveFileW', src, dest);
}


This post was edited on 06-09-2009 at 08:09 PM by matty.
05-25-2009 05:36 PM
Profile E-Mail PM Find Quote Report
ainain
New Member
*


Posts: 8
Joined: Jan 2009
O.P. RE: copy file
thanks a lot, how about "rename"?
05-30-2009 03:38 PM
Profile E-Mail PM Find Quote Report
Mnjul
forum super mod
******

Avatar
plz wub me

Posts: 5396
Reputation: 58
– / Other / Flag
Joined: Nov 2002
Status: Away
RE: copy file
Just replace "CopyFileW" with "MoveFileW" :)
05-30-2009 03:49 PM
Profile PM Web Find Quote Report
wincy
Junior Member
**


Posts: 67
Reputation: 4
34 / Male / Flag
Joined: Feb 2008
RE: copy file
Here's my code:

CopyFile('c:\\boh.txt', 'c:\\bah.gif');
function CopyFile(src, dest) {
    Interop.Call('user32', 'CopyFileW', src, dest, false);
}


Debugger shows this error:
CallDll has failed collocation of the function "CopyFileW"
(in row containing "Interop.Call..ecc")

What's the problem? :(

// EDIT: I see that works using "kernel32" instead of "user32"...

This post was edited on 05-30-2009 at 10:41 PM by wincy.
05-30-2009 10:29 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: copy file
I'd like to ask a related question.  How can you delete a file?  And does it work with folders?
07-14-2009 01:10 PM
Profile E-Mail PM Find Quote Report
NanaFreak
Scripting Contest Winner
*****


Posts: 1476
Reputation: 53
32 / Male / Flag
Joined: Jul 2006
RE: copy file
http://www.pinvoke.net/ that site should help you with your kernel32 and user32 stuff ;) though you may have to get someone to help translate it from vb or C into the JScript version for plus...

This post was edited on 07-14-2009 at 01:17 PM by NanaFreak.
07-14-2009 01:15 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: copy file
quote:
Originally posted by whiz
I'd like to ask a related question.  How can you delete a file?  And does it work with folders?
No offence but you should start trying the easy stuff yourself first then post if you cannot get it to work...

Javascript code:
function DeleteFile(lpstrFile) {
    return Interop.Call('kernel32', 'DeleteFileW', lpstrFile) !== 0;
}


To remove a directory:
Javascript code:
/* do not include trailing slashes, pass the path as c:\\test */
function RemoveDirectory(sPath) {
    var WIN32_FIND_DATA = Interop.Allocate(592);
    var hSearch = Interop.Call('kernel32', 'FindFirstFileW', sPath+'\\*.*', WIN32_FIND_DATA);
    var hResult;
    while(hResult != 0){
        if(!(WIN32_FIND_DATA.ReadDWORD(0) & 0x10 /* FILE_ATTRIBUTE_DIRECTORY */)){
            Interop.Call('kernel32', 'DeleteFileW', sPath+'\\'+WIN32_FIND_DATA.ReadString(44));
        } else {
            RemoveDirectory(sPath+WIN32_FIND_DATA.ReadString(44));
            Interop.Call('kernel32', 'RemoveDirectoryW', '\\\\?\\'+sPath+'\\'+WIN32_FIND_DATA.ReadString(44));
        }
        hResult = Interop.Call('kernel32', 'FindNextFileW', hSearch, WIN32_FIND_DATA)
    }
    Interop.Call('kernel32', 'FindClose', hSearch);
}


This post was edited on 07-14-2009 at 02:55 PM by matty.
07-14-2009 01:51 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: RE: copy file
quote:
Originally posted by matty
Javascript code:
function DeleteFile(lpstrFile) {
    return Interop.Call('user32', 'DeleteFileW', lpstrFile) !== 0;
}


To remove a directory:
Javascript code:
function RemoveDirectory(sPath) {
    var WIN32_FIND_DATA = Interop.Allocate(592);
    var hSearch = Interop.Call('kernel32', 'FindFirstFileW', sPath+'\\*.*', WIN32_FIND_DATA);
    var hResult;
    while(hResult != 0){
        if(!(WIN32_FIND_DATA.ReadDWORD(0) & 0x10 /* FILE_ATTRIBUTE_DIRECTORY */)){
            DeleteFile(sPath+WIN32_FIND_DATA.ReadString(44));
        } else {
            RemoveDirectory(sPath+WIN32_FIND_DATA.ReadString(44));
            Interop.Call('kernel32', 'RemoveDirectoryW', '\\\\?\\'+sPath+WIN32_FIND_DATA.ReadString(44));
        }
        hResult = Interop.Call('kernel32', 'FindNextFileW', hSearch, WIN32_FIND_DATA)
    }
    Interop.Call('kernel32', 'FindClose', hSearch);
}


quote:
Originally posted by JavaScript Debugger
Error: unknown (code: -2147467259)
Javascript code:
/* error: */ return Interop.Call('user32', 'DeleteFileW', lpstrFile) !== 0;

07-14-2009 02:22 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: copy file
Made a mistake should be kernel32 not user32.
07-14-2009 02:29 PM
Profile E-Mail PM Find Quote Report
Pages: (3): « First [ 1 ] 2 3 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On