0

I have the requirement to print the full path and file names of files selected in windows directory.

the approach I have taken is

1. create key in registry to give option in context menu
2. attached the context menu option to execute my java program

now the issue I have , I want to select a few files ,

1. then right click on it
2. then execute my java program 
3. and have the list of files selected in my java program as an input

i am not able to achieve point 3

any guidance how to approach it or better alternative

1 Answers1

1

I think there is 2 possible approaches here.

  1. You can custom Send to context menu, it supports passing multiple selected files. I prefer this one. It's quite simple to implement.

    For example:

    Ex.java

    import java.io.IOException;
    
    public class Ex {
        public static void main(String[] args)
                throws IOException {
            for (String argument : args) {
                System.out.println(argument);
            }
            System.in.read();
        }
    }
    

    Compile it to Ex.class.

    Create a shortcut named Test Send To in C:\Users\[username]\AppData\Roaming\Microsoft\Windows\SendTo point to:

    "path\to\java.exe" -cp "path\to\Ex.class folder" Ex
    

    Now try selecting multiple files and then right-click Send To > Test Send To, you will see the list of selected files onscreen.

  2. You can implement interprocess communication to tell the existing instance that you want to add more files to proceed.

Cà phê đen
  • 1,883
  • 2
  • 21
  • 20
  • @HussainAkhtarWahid'Ghouri' Please check my updated answer. I just add a small sample for point 1. – Cà phê đen Nov 28 '16 at 10:33
  • @HussainAkhtarWahid'Ghouri' Sorry for my unclear explanation. I mean to create a shortcut whose target is `"path\to\java.exe" -cp "path\to\Ex.class folder" Ex`. ![Here is the image](http://i.imgur.com/cY0w9Du.png) – Cà phê đen Nov 28 '16 at 20:35
  • @HussainAkhtarWahid'Ghouri' Maybe your problem is still. Here I can find some related posts: [Create shortcut programatically in Java](http://stackoverflow.com/questions/19629034/create-shortcut-in-windows-programmatically) [Custom "Send to" context menu"](http://www.howtogeek.com/howto/windows-vista/customize-the-windows-vista-send-to-menu/) – Cà phê đen Nov 30 '16 at 07:15