Ace128 has asked for the wisdom of the Perl Monks concerning the following question:

Hey!

Using Win32::Clipboard I can get files. Example:
#!perl -w use strict; use Win32::clipboard; use Time::HiRes qw( usleep ); my $clip = Win32::Clipboard("remove dots and underscore in the clipboa +rd content"); for (;;) { $clip->WaitForChange(); if (Win32::Clipboard::IsFiles()) { my @files = Win32::Clipboard::GetFiles(); print join("\n", @files); } $clip->Empty(); usleep 000_500; }
But, how do I set files in clipboard that I wanna copy/move when I paste in explorer (and even in X in linux)? Like:
Win32::Clipboard::SetFiles(\@files);
I seems that Win32::Clipboard doesnt have support for this... But I bet it works with Win32::API! But I have no idea how!

Anyone wanna help me out?

Thanks,
Ace

Replies are listed 'Best First'.
Re: Move/Copy files using Clipboard!
by zentara (Cardinal) on Oct 13, 2005 at 11:08 UTC
    Check out "Clipboard" and "Tk::Clipboard".

    I'm not really a human, but I play one on earth. flash japh
      "Clipboard" didnt seem to support files. With Tk::Clipboard I tested:
      use Tk; use Tk::clipboard; use strict; use warnings; #use diagnostics; #print Clipboard->paste; my $mw = new MainWindow; #my $clip = Tk::clipboard::clipboardGet( -type => 'FILE_NAME' ); $mw->clipboardClear; $mw->clipboardAppend(-format=>"FILE_NAME", -type => 'FILE_NAME', "--", + "C:\\test\\gaga.txt"); #print $clip; MainLoop;
      No luck. Pasting in explorer having this runing didn't do anything with the file.
Re: Move/Copy files using Clipboard!
by BrowserUk (Patriarch) on Oct 14, 2005 at 06:21 UTC

    This isn't something that can be easily done with win32::API.

    If you are setup to build your own packages, you could try applying the following patch to Win32::Clipboard v0.52. It adds a SetFiles() method. It includes the code changes plus an extra test, but no changes to the documentation.

    If it proves usable I'll offer it to the owner, but be prepared to back it out. XS isn't my thing.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
      Wow! Hope it will be official soon :)

      But, err, where did you find this patch? Couldn't find that on cpan... only http://search.cpan.org/~jdb/libwin32/Clipboard/Clipboard.pm (which is v0.52)

      Update: Seems like its you're personal update, or?
        But, err, where did you find this patch?

        I just finished writing it. I wanted this myself a couple of years ago, but couldn't get it to work. This time I did.

        Please let me know how you get on with it. If it works for you also, then I'll forward the patch to whomever owns it (there seem to be two owners?), and it's up to them whether they wish to add it.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re: Move/Copy files using Clipboard!
by radiantmatrix (Parson) on Oct 13, 2005 at 19:37 UTC

    The Win32 family of modules will not work under Linux, it's Windows-only. Some Linux Desktop Environments (e.g. KDE, Gnome) support file-pasting, but only with calls to their libraries (e.g. Qt and GTK, respectively).

    As for the Windows API, you want Microsoft's documentation on that matter. Anything in the API can be called using Win32::API, and the module docs explain the mechanics.

    <-radiant.matrix->
    A collection of thoughts and links from the minds of geeks
    The Code that can be seen is not the true Code
    "In any sufficiently large group of people, most are idiots" - Kaa's Law
Re: Move/Copy files using Clipboard!
by zentara (Cardinal) on Oct 13, 2005 at 16:33 UTC
    Yeah, the clipboard can be tricky to deal with on linux. You can always use xclip
    system("xclip -i -selection clipboard $filename");
    There are 3 different clipboards, the 'primary','secondary', and 'clipboard'. Try "xclip -h" for xclip help. If you find the right syntax for using Tk::Clipboard let us know. :-)

    I'm not really a human, but I play one on earth. flash japh