Windows: Best way to access files regardless of drive letters (UNC?, Network Share?)

Posted on 2011-05-11
Last Modified: 2012-05-11
I have several computers with the same directory of files.  The only problem is that on some computers the directory is on the C: drive and on others it's on the D: drive.

How do I abstract this so that my application code can access this directory in a uniform way:

Can UNC be used for this?  I don't need to go over the network.

Question by:ZuZuPetals
    LVL 4

    Expert Comment

    UNC is the easiest way \\computername\drive$
    LVL 17

    Expert Comment

    The simplest way would be to map them all to a common mapped drive if that options is available.

    Othewise create a share for that particular folder on each of the machines and access it via the share.
    LVL 18

    Expert Comment

    on startup check  for existing  of  directory  with "if else" in  all possible locations.

    LVL 29

    Expert Comment

    by:Randy Downs
    Maybe check UNC path
    if file exists on C - Then run your code on C
    else check file exists on D - Then run your code on D
    LVL 4

    Accepted Solution

    You can share the directory as a common name on all the computers for share as "datafolder" for example and then use the path \\localhost\datafolder\ to access it on each PC. the name Localhost always points to your own PC.

    Otherwise just record where on each PC the the folder is in the registry or an ini file or even an environment variable and have your program look it up each time.
    LVL 2

    Author Closing Comment

    Exactly what I was looking for.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
    This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.
    The viewer will learn how to back up in Windows 7 with native tools. This should be the first step. Third party tools should also be used. Access the Backup and Restore options: Click on the windows 7 start ball in the lower left corner of the scree…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now