How to detect which physical drive a given file is on

Given a file that exists, is there a way within Java to detect what physical drive that file is on? I don't care how that drive is denoted, as long as it is uniquely specified. This can be through a hard drive serial number, or any other way. The specifics of the drive do not matter, I only care about uniquely identifying physical drives. If it matters, I'd like to also be able to determine if said drive is a flash drive, however programmatically I won't care that it is a flash drive, just that it is a separate drive itself.
If this isn't possible through Java, could someone point me in the direction of how to determine this through another language, possibly using JNI?

mgolowka wrote:
Given a file that exists, is there a way within Java to detect what physical drive that file is on?
Check if this helps you, I'm not sure the effects when this is executed in a Unix based environment.
     public static void main(final String[] args) {
          final String fileName = "my_file.myext";
          final File file = new File(fileName);
          final File roots[] = File.listRoots();
          final String rootOfTheFile = file.getAbsolutePath().substring(0,
                    file.getAbsolutePath().indexOf(File.separator))
                    + File.separator;
          System.out.println("File is present in - " + rootOfTheFile);
          for (final File file2 : roots) {
               System.out.println("Root in system - " + file2.getPath());
     }And the output for the code is as follows, of which Y and Z are network mapped drives.
File is present in - D:\
Root in system - C:\
Root in system - D:\
Root in system - E:\
Root in system - F:\
Root in system - Y:\
Root in system - Z:\

Similar Messages

  • Disk error - but which physical drive is it ?

    Hi - I'm occasionally seeing in Sever Manager > Events > ID 153 - "The IO operation at logical block address 10028 for
    Disk 6 was retried"
    I have a boot-drive (obviously), and a Storage Space consisting of 4 drives setup as a 2-way mirror
    In CompMgmt, I can (only) see:
    Disk4 - System Reserved & (C:)
    Disk5 - Storage Space (D:)
    How can I find out which physical drive is Drive 6 ?
    -Tom

    Hi Luc - this is what I've got:
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\disk\Enum]
    "0"="SCSI\\Disk&Ven_WDC&Prod_WD10EACS-65D6B0\\4&314aa983&0&000000"
    "1"="SCSI\\Disk&Ven_WDC&Prod_WD10EACS-65D6B0\\4&314aa983&0&010000"
    "2"="SCSI\\Disk&Ven_WDC&Prod_WD10EACS-65D6B0\\4&314aa983&0&020000"
    "3"="SCSI\\Disk&Ven_&Prod_ST31000340AS\\4&314aa983&0&030000"
    "4"="SCSI\\Disk&Ven_ATA&Prod_FUJITSU_MJA2500B\\5&23edb610&0&000100"
    "5"="STORAGE\\Disk\\{d8cabde7-ccd9-11e1-bbc5-441ea13ee209}"
    "Count"=dword:00000006
    "NextInstance"=dword:00000006
    Looking at the details of Event 153 (there were 40 of them all within 1 minute), it actually shows : "\Device\Harddisk6\DR8"
    I've Google'd this and (some) hits point to it possibly being a USB device - perhaps a USB stick ?
    (My drives are all SATA, and hang off an IBM BR10i SAS controller)
    Anyway, there have been no further errors
    -Tom

  • How can detect that cdrom drive were opened and closed?

    How can detect that cdrom drive were opened and closed?

    I'm sure there are more elegant and complicated ways to accomplish this using Windows SDK function calls to kernel32.dll or something extravagant like that, but if you want the bare-bones easy way to check if the CD-ROM tray is currently opened, then simply use System Exec to query the CD-ROM drive from the command line. One example of this is shown below.
    Use the command line function cmd /c d:, where d: is your CD-ROM drive. If the Standard Error output from System Exec.vi is "The device is not ready." followed by a carraige return and line feed, then voila, your CD-ROM drive is open. If not, it's closed. Anyone have a better idea? I'm sure one exists...
    Message Edited by Jarrod S. on 02-16-2006 12:23 PM
    Jarrod S.
    National Instruments
    Attachments:
    CDROM_Check.JPG ‏22 KB

  • How to digitize a physical book (scanned pfd file) to a kindle format with Indesign? pages are 8x11.

    How to digitize a physical book (scanned pfd file) to a kindle format with Indesign? pages are 8x11.
    I have all scanned pages, but the kindle format offered on the Indesign options is bigger. What should I do? Do I start a book from scratch with the scanned pictures or do I leave the pages with the white space on them with the kindle option of Indesign.

    Hi barbaraegarza,
    For your situation, you could try using alternatives like PDF4Kindle, Calibre, or Papercrop.  But based on what I've read and my quick experiment, depending on the complexity of  your PDF, it may be more effort than it's worth to try to convert a PDF into a legible Kindle, ePub, or any other e-reader file.
    I did a quick test on Calibre with a 16-page PDF that contained multiple columns and images.  The results were illegible!  It ran the lines from each column together, making the text difficult to comprehend.  Calibre explains why PDFs are difficult to convert -- Ebook Conversion — calibre User Manual.  I have not tried the other two applications that I suggested above, but I would assume that the results would be very similar.
    I don't know what kind of results you got when you converted it in InDesign, but if your first test turned out fine and it was just the size of the file that you are concerned about, you could use Acrobat to reduce your PDF's file size and convert it to the Kindle format in InDesign again.
    Hope this helps.  Good luck!

  • How to detect USB Flash Drive name in LabVIEW

    Hi there
    I was looking for how to detect a USB Flash Drive name in Labview
    appearently every time i insert USB Flash Drive in a computer, windows assign it a different name
    once "J:" and sometimes "M:"
    Is there anyway to obtain USB Flash Drive name programmatically in Labview ?
    Because in my program an user shouldn't be able to access HDD Drives except his USB Flash Drive (for inserting some file ...)
    thank you and excuse me for my poor english 

    I was able to get the demo.vi to load, but it could not load the other two because there is no block diagram associated with those.  I'm not sure why this is.  I haven't had any issues with other llbs before.
    Reese, (former CLAD, future CLD)
    Some people call me the Space Cowboy!
    Some call me the gangster of love.
    Some people call me MoReese!
    ...I'm right here baby, right here, right here, right here at home

  • How to detect which data type is passed in ?

    Hello!
     I've built a VI function. But I want to make it more secure - that function could detect which data type is wired to the inputs and allow wiring only certain data types. How can I do this?
     Thanks
    Message Edited by ACiDuser on 05-23-2009 08:13 PM
    Solved!
    Go to Solution.

    I'm assuming you're talking about numeric datatypes. In this case that information is not available to you at the subVI level. The LabVIEW compiler will have already changed the datatype to match what your subVI expects if someone wires something of a different type.
    You could use a variant as your input. Then in the subVI you can use the Variant to Flattened Data to get the type. The OpenG LabVIEW Data Tools VIs will be useful if returning an enum specifying the datatype. Specifically, using the "Get TDEnum From Data VI".
    Now that we've gotten that out of the way, let's talk about the why. Why do you need to do this? What are you trying to "secure"?

  • How to know which mirrored drives after mirroring.

    Hi All
    Any one used Veritas NetBackup together with Xserve Raid? After i mirrored drives 1 and 2 and the other mirrored drives 3 and 4, i have a problem knowing which is drives 1,2 and 3,4 in Veritas NetBackup, because after trying out backup on 1 and 2 .. it works but not on 3 and 4.
    Thanks if anyone has some pointers regarding this issue.
    Matt

    I don't know how Veritas references disks (whether it uses volume names like the Finder, or device IDs like /dev/disk0), so I can't answer your question directly, however, the command diskutil list will list all disks in your system, as well as any arrays, showing you the breakdown of which disks constitute which arrays/volumes.

  • How to clone a physical drive?

    Hi, I have been trying to figure out how to clone my MacBooks hard-drive. It has OSX, plus Bootcamp and XP Pro partitions. My destination drive is an exact duplicate physical drive in an external USB enclosure. I want to clone the entire internal drive to the external drive, including all partitions and boot data. The DiskUtility, even when booted from CD, only supports cloning individual partitions. SuperDuper and other utilities seem to work the same. I tried the linux tool, G4L, and it did not recognize the external USB drive. I am trying to clone so that if the internal drive ever croaks, I can just drop in the drive thats currently in the external case - and have no down time. I only need to backup my machine this way once a month, so it doesnt matter how long the process takes - as long as it works! Any suggestions?

    Hi wh31415,
    You can clone both your OS X and Windows partitions from within OS X. Partition your external so that the Windows portion is large enough to hold a disk image of the Windows installation on your main drive. Leave the rest for OS X. You can do this with Disk Utility.
    Once you have the external partitioned, use WinClone to clone the Windows drive. You run it right from OS X. It creates a compressed disk image that can be restored from OS X also. It's free and works great.
    For OS X, use either SuperDuper! or Carbon Copy Cloner. Both can be run right from the OS X installation you're booted from. Just don't do anything else while it's cloning. Both are free, though the paid version of SuperDuper! is worth every cent for updating your backup.

  • How to detect which Anti Virus is installed?

    I want to know how can I detect which anti virus is installed on the system using C#?
    Jassim Rahma

    You can use WMI to query this information.  The code to do so would work like this:
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\SecurityCenter2", "SELECT * FROM AntiVirusProduct");
    ManagementObjectCollection result = searcher.Get();
    if (result.Count > 0)
        foreach (ManagementObject item in result)
            Console.WriteLine("Your computer is protected by: {0}", item["displayName"]);
    else
        Console.WriteLine("Your computer is not protected!");
    Note that the location on that first line might be "root\SecurityCenter" on some systems.  It might be best to run this portion of code for both "root\SecurityCenter" and "root\SecurityCenter2".
    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light Wiki • LinkedIn • ForumsBrowser

  • How to detect which application connects to the in...

    Hello,
    I have a E71 and for a week or so the phone drains the battery quite fast.
    I have seen in the journal that an wi-fi connection is opening every 2-3 minuntes for less the half a minute.
    The weird thing is that the WLAN is disconected and WLAN SCAN is OFF, but the icon that shows a wi-fi connection appaers every 2-3 minutes.
    So how to detect the damn application that makes wi-fi conections by my back?
    Thanks!

    Check messaging and social media apps connection and sync settings.
    ‡Thank you for hitting the Blue/Green Star button‡
    N8-00 RM 596 V:111.030.0609; E71-1(05) RM 346 V: 500.21.009

  • How to detect which applications that are currently running

    Hi there. Is there a way to detect which applications that are currently running on my machine? Is there a class that can get all of the running applications, you know, like the taskmanager.
    //peter

    What you are asking for is indeed not possible through "100% Pure Java," because each operating system that runs Java Virtual Machines can handle the running processes differently (think about the differences between a process scheduler for, say, Windows NT and your Palm Pilot, both of which could have a JVM running).
    That means there are essentially 2 avenues to persue for this:
    1. Use an external "user-level" command (like ps on a UNIX-like OS) and parse the results (this is what people are referring to when they say "Runtime.exec()". There have been some nice exec() frameworks posted around here before, so I'd recommend searching around a bit for more info.
    I also found this link (from Google) which apparently shows the javadocs where someone has attempted something similarly on the Linux platform before...that's all I know about it:
    http://www.cougaar.org/software/9.2/javadoc/api/org/cougaar/tools/server/system/linux/LinuxProcessStatusReader.html
    2. Use a JNI (Java Native Interface) call to an externally provided C function to get the info you need. Here's a link to the Java 1.4 JNI information:
    http://java.sun.com/j2se/1.4/docs/guide/jni/
    Hope this helps! (But it's not going to be a quick and easy problem to work with)...
    -J

  • How to detect which class caused missing plug-in alert?

    Hi,
    I have a plug-in with the bellowing class definition, there is no any customized persist class.
    resource ClassDescriptionTable(kSDKDefClassDescriptionTableResourceID)
              Class
                        kMyActionComponentBoss,
                        kInvalidClass,
                                  IID_IACTIONCOMPONENT, kMyActionComponentImpl,
                                  IID_IPMPERSIST, kPMPersistImpl
              Class
                        kMyDialogBoss,
                        kDialogBoss,
                                  IID_IDIALOGCONTROLLER, kMyDialogControllerImpl,
                                  IID_IOBSERVER, kMyDialogObserverImpl,
    In programming guide it says "If your plug-in does not store data in documents, you do not need to take any special precautions" in section "Guidelines for handling a missing plug-in".
    However now, there may be missing plug-in message for this plug-in when open a document saved with this plug-in installed.
    My question is: is there any way to detect which class/implement caused the plug-in is required?
    I can get some info about missing plug-in from IContentMgr, but there is no info about the detail classes.
    Any idea?
    Thanks,
    Aidy

    Regarding global (or not) text adornments:
    An adornment is something attached to a larger entity, e.g. the various handles of page items, or additional marks within text.
    Some adornments are remembered individually per addressed entity (page item adornments are probably in IPageItemAdornmentList), while others (the global text adornment IGlobalTextAdornment) are just assumed to be there for all potential targets (all wax runs) and have no persistent footprint where the ITextAdornments do.
    For more details please refer to the documentation or just search the SDK.
    Dirk

  • How to detect which JVM is installed on a server

    Hi,
    Our company is using a robot to scan workstation to detect which soft is installed on machines
    We would like to have an idea of which JVM is installed on workstations. Our robot can detect filename, filesize, signature (properties).
    Where can I find for each JVM the filename to detect, its filesize and eventually the signature associated
    Many thanks in advance for your help

    To get the version of java type
    java -version
    From this you can build a set of signatures for each version. You may find you inventory program will allow you to run a script on the workstation in which case you can get the exact version automatically.

  • How to find the physical path of a file

    Usually, one can use absFileNmae() method to find the path of a file in Java. The problem is that it may only return a mapped path when a Servlet or JSP is running in a special server. For example, when I run a servlet "MyProgram" in JRun, absFileName() only returns "c:\JRun\jsm-default\MyProgram", which is just a mapped path, not a real physical path.
    By the way, in ASP, one can use server.mapPath("MyASPProgram.asp") to obtain the real physical path of the file.
    Your solution is welcome.
    YC

    Usually, one can use absFileNmae() method to find the path of a file in Java. The problem is that it may only return a mapped path when a Servlet or JSP is running in a special server. For example, when I run a servlet "MyProgram" in JRun, absFileName() only returns "c:\JRun\jsm-default\MyProgram", which is just a mapped path, not a real physical path.
    By the way, in ASP, one can use server.mapPath("MyASPProgram.asp") to obtain the real physical path of the file.
    Your solution is welcome.
    YC

  • How to display the physical location of my file ?

    I got to display the physical lacation of a file in my HDD in a textbox. I'am using 'fileChooser' to get access to the HDD. Is there a method i can use in fileChooser which will display the path to the file?
    thanks

    getSelectedFile().getAbsolutePath()
    http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html
    http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html
    -Puce

Maybe you are looking for