aspose file tools*
The moose likes Java in General and the fly likes Finding Location of a recently created file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Finding Location of a recently created file?" Watch "Finding Location of a recently created file?" New topic
Author

Finding Location of a recently created file?

Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Hi Ranchers,

I have a peculiar requirement.

After a drag & drop operation into native OS... Is there a way I could get to know the drop the drop location?

If thats a big ask. What is the best way to find the location of a file from Native OS with just file/directory name?

TIA

[ August 16, 2005: Message edited by: Ravi Sathish ]
[ August 21, 2005: Message edited by: Ravi Sathish ]
Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Looks like there's no response here... Sheriff can you please move this to java.io. forum?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

I don't think anybody understands what you're asking -- I don't. In particular, I have no idea what the "location" of a file is, if it's not the same as the complete path? If you mean the x,y location of a icon for a file on the screen, not even the OS itself will know this, in general. It's an incidental detail -- and it's not even unique, as most "file managers" will allow you to see a single file more than once at a time.

I can tell you that in general, the way DnD is supposed to work is that data is transferred from the "drag source" to the "drop target", and it's up to the "drop target" to do something with it; there's really no mechanism for more information to be exchanged, although if you're writing the code for both, then it's generally possible to work something out.

Why not tell us what your problem, exactly, and maybe we can help you figure out how to solve it, rather than telling us your solution and asking us to tell you how to code it.


[Jess in Action][AskingGoodQuestions]
Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Fair enough...

Currently my application REQUIRES ABSOLUTE PATH OF A FILE for any kind of processing. In my application files are stored in custom format and I have API's to convert from/to files.

I'm trying to implement DnD in 2 cases:

Case 1> Between 2 components within my Java App -> works alright [I'm using Drag & Drop Listeners]... here no files are involved... I just play around with my objects... there's no overhead

2> Between a component in my Java App & Desktop on Native OS (works partially on XP & still not possible on Linux ] DnD b/w Linux & Swing

When I drop files from Windows into my App; I process it as DataFlavor.javaFileListFlavor and then do the actual processing where in I get the ABSOLUTE FILE PATH from List of files dropped into my component

Similarly before DNDing to the OS I need to convert my custom format into a java.util.List of files. Now these files do not exist as such right? So I create a list of new files(reflecting my format) in tempDir and use ABSOLUTE PATHS of these files to fill data from my app. On DnD the appropriate behavior happens

But this process of actually filling in data is complete Overhead when I DND between 2 components inside my app.

I'm willing to create files everytime a drag operation is started. But if I could get the drop Location (absolute file path) after DnD to OS. I can fill in data into the files using my API's.

I will explain my story better in a better way if someone is willing to listen

TIA
[ August 16, 2005: Message edited by: Ravi Sathish ]
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410

2> Between a component in my Java App & Desktop on Native OS (works partially on XP & still not possible on Linux ]

I asked about this recently in the AWT/Swing forum but got no response so I am guessing DnD between Windows and a Java app is not possible.
Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Stuart,

Atleast it works partially for me on Windows XP (havent got it working yet on Linux). My problem being bit peculiar hence I able to complete implementation. Let me know what you are trying viz. DND between Swing & Desktop

Ravi
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
Well my requirements were to find the name and path of a file dragged from the desktop or another folder into my Swing app. But it has already been mentioned that such additional information as file paths is not available to a drag target. However, *any* code that got this even half working would be very much appreciated.
Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
I dunno if I understand your requirements correctly. But this is what I do when dragging a file from desktop to Swing component:

Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Do you still want this thread moved to the I/O forum? I kinda think that the title of the thread may stop some people who otherwise might have helpful information from reading it.
[ August 19, 2005: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

So your question is: your client wants to know where the data is being sent, so it can consider this when creating the DnD data? You're asking about an optimization, because when DnD'ing inside the app, you can exchange data more cheaply, is that right?

You can do this by using a special flavor for intra-app DnD. The DropTarget can ask for this special flavor first, and the generic file list second; if you see the special flavor being asked for then you know the drop target is your own app.
Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Ernest Friedman-Hill wrote:
So your question is: your client wants to know where the data is being sent, so it can consider this when creating the DnD data? You're asking about an optimization, because when DnD'ing inside the app, you can exchange data more cheaply, is that right?


Not really... The problem for me my components should be capable of accepting Dataflavors.javaFileListFlavor along with custom flavor b'coz a user can drop a file from desktop into my application as the code snippet I have posted describes.

Recently I found this web-blog which has some pointers which has lots of pointers to my problem. I'll keep u guys posted about my progress...redsolo's web blog
[ August 21, 2005: Message edited by: Ravi Sathish ]
 
 
subject: Finding Location of a recently created file?
 
Similar Threads
any ideas on how long before password for downloading logo
File Download dialog
Whats the best way to change background of treeNode in JTree
JTree can TransferHandler & DnD Listeners coexist ?
How does Performance Review work?