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:
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: copy file
quote:
Originally posted by matty
Made a mistake should be kernel32 not user32.
No error now, but it still does nothing.  :S
07-14-2009 02:51 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
The delete file does nothing or the recursive delete does nothing?

I updated the recursive function.

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


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: copy file
Assuming that I call it with "RemoveDirectory(/* path */)", both the folder and the files inside remain, with no apparent actions taken.
07-14-2009 02:58 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
Try this:
js code:
RemoveDirectory('C:\\This\\Is\\The\\Directory\\To\\Delete\\');

function RemoveDirectory(sPath) {
    var WIN32_FIND_DATA = Interop.Allocate(592);
    var hSearch = Interop.Call('kernel32', 'FindFirstFileW', sPath+'*', WIN32_FIND_DATA);
    var hResult = -1;
    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 03:08 PM by matty.
07-14-2009 03:03 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: copy file
Still nothing...?
js code:
RemoveDirectory("C:\\Documents and Settings\\ __________\\My Documents\\New Folder");
I made a folder in My Documents called "New Folder", and added two Notepad documents.  But they're still there...
07-14-2009 03:19 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
quote:
Originally posted by whiz
Still nothing...?
js code:
RemoveDirectory("C:\\Documents and Settings\\ __________\\My Documents\\New Folder");
I made a folder in My Documents called "New Folder", and added two Notepad documents.  But they're still there...
js code:
RemoveDirectory("C:\\Documents and Settings\\ __________\\My Documents\\New Folder\\");
I forgot to mention I made the code dependent on having trailing slashes.
07-14-2009 03:27 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: copy file
Well, the files have gone.  Does it not delete the folder as well?
07-14-2009 03:33 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
It should I will look at it later. I am not at home so I cannot test it.

Take a look at this and post the Debug information.
js code:
RemoveDirectory('C:\\This\\Is\\The\\Directory\\To\\Delete\\');

function RemoveDirectory(sPath) {
    var WIN32_FIND_DATA = Interop.Allocate(592);
    var hSearch = Interop.Call('kernel32', 'FindFirstFileW', sPath+'*', WIN32_FIND_DATA);
    var hResult = -1;
    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));
            if ( Interop.Call('kernel32', 'RemoveDirectoryW', '\\\\?\\'+sPath+WIN32_FIND_DATA.ReadString(44)) === 0 ) TraceWin32Error()
        }
        hResult = Interop.Call('kernel32', 'FindNextFileW', hSearch, WIN32_FIND_DATA)
    }
    Interop.Call('kernel32', 'FindClose', hSearch);
}

function TraceWin32Error(){
    var LastError = Interop.GetLastError();
    if(LastError != 0) {
        var MsgBuffer = Interop.Allocate(1024);
        Interop.Call("Kernel32", "FormatMessageW", 0x1000, 0, LastError, 0, MsgBuffer, 1024, 0);
        Debug.Trace(MsgBuffer.ReadString(0));
    }
}

This post was edited on 07-14-2009 at 06:33 PM by matty.
07-14-2009 06:17 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: copy file
Well, it deleted the two files in the folder, but...
quote:
Originally posted by JavaScript Debugger
code:
The system cannot find the file specified.

The system cannot find the file specified.

The filename, directory name, or volume label syntax is incorrect.

The system cannot find the file specified.

The filename, directory name, or volume label syntax is incorrect.

The system cannot find the file specified.

The system cannot find the file specified.

The filename, directory name, or volume label syntax is incorrect.

The system cannot find the file specified.

The directory is not empty.


Folder contents:
code:
| Test // root folder, not deleted
+-| Test1 // folder, not deleted
| +-> New Notepad++ Document.txt // not deleted
+-> New Notepad++ Document.txt // deleted successfully
+-> New Notepad++ Document (2).txt // deleted successfully

When tested without the "Test1" folder, the two documents were removed, but the folder remained, and the debugger showed the same.  :S

This post was edited on 07-14-2009 at 07:30 PM by whiz.
07-14-2009 07:24 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
I did a little testing and noticed a few things.

- Firstly FindFirstFileW and FindNextFileW will find . and .. as well
- I forgot to append the path with slashes

js code:
RemoveDirectory('C:\\Documents and Settings\\__________\\My Documents\\New Folder', true);

function RemoveDirectory(sPath, bFirstFolder) {
    sPath='\\\\?\\'+sPath;
    var WIN32_FIND_DATA = Interop.Allocate(592);
    var hSearch = Interop.Call('kernel32', 'FindFirstFileW', sPath+'\\*', WIN32_FIND_DATA);
    var hResult = -1;
    var sFile;
    while(hResult != 0){
        sFile = WIN32_FIND_DATA.ReadString(44);
        if (sFile !== '.' && sFile !== '..') {
            if(!(WIN32_FIND_DATA.ReadDWORD(0) & 0x10 /* FILE_ATTRIBUTE_DIRECTORY */)){
                Debug.Trace(sPath+sFile);
                Interop.Call('kernel32', 'DeleteFileW', sPath+'\\'+sFile);
            } else {
                Debug.Trace(sPath+sFile);
                RemoveDirectory(sPath+'\\'+sFile false);
                if ( Interop.Call('kernel32', 'RemoveDirectoryW', sPath+'\\'+sFile) === 0 ) TraceWin32Error()
            }
        }
        hResult = Interop.Call('kernel32', 'FindNextFileW', hSearch, WIN32_FIND_DATA)
    }
    Interop.Call('kernel32', 'FindClose', hSearch);
    if (bFirstFolder === true) Interop.Call('kernel32', 'RemoveDirectoryW', sPath)
}

function TraceWin32Error(){
    var LastError = Interop.GetLastError();
    if(LastError != 0) {
        var MsgBuffer = Interop.Allocate(1024);
        Interop.Call("Kernel32", "FormatMessageW", 0x1000, 0, LastError, 0, MsgBuffer, 1024, 0);
        Debug.Trace(MsgBuffer.ReadString(0));
    }
}

No idea if this will work I would have to do a bit more troubleshooting as to why it doesn't.

This post was edited on 07-15-2009 at 12:48 PM by matty.
07-15-2009 12:43 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