PDA

View Full Version : Can anyone explain the Windows file system structure to a unix geek




foidulus
Jul 5, 2009, 04:30 PM
I've been charged with the unenviable task of porting one of the applications we develop at work from real OSs(OS X and Linux) to a toy OS(XP)

While the app is in Java and most of the stuff just works(works perfectly on OS X and Linux), I'm really struggling with understanding the whole windows file structure as was wondering if anyone here could explain how this works to a hardcore unix geek.

First, is the drive letter necessary? Is there any analogue to / on windows systems? Our application uses NAS and if I didn't have to know the drive letter, that would be a lifesaver.

Second, which directory(ies) do Windows users expect stuff to go in? Is it ok to make a directory at the c:\ root?

Thanks!



lee1210
Jul 5, 2009, 04:59 PM
I don't know about file system access using drive letters, etc., but this stackoverflow page has some code to grab the user's home directory:
http://stackoverflow.com/questions/570401/in-java-under-windows-how-do-i-find-a-redirected-desktop-folder
IMO on every system this is where to put things, rather than the root of a filesystem/drive/etc.

-Lee

fehhkk
Jul 5, 2009, 05:09 PM
The Windows structure has almost been the same since Windows 95.

By default, windows is installed in drive C: under C:\Windows... which is the first hard drive. The first two (A: and B:) are reserved for floppies, since this nomeclature carries back from the DOS days.

The / root folder in UNIX, would be the equivalent of C:\ ... where \ is the root folder.

C:\Windows\System32 contains the system libraries for windows and the shared stuff, kind of like /usr/lib

While in unix/linux you have user's data stored under /home/<username> , in Windows it'll be by default, in C:\Windows\Users\<username>

The first drive letter is used to address absolute paths, just like in Unix. In Windows, you generally change drives, and once you're in that drive, you can address paths within the same drive without addressing the first drive name. For example:

cd c:
copy \windows\notepad.exe d:\mydir

Flynnstone
Jul 5, 2009, 09:10 PM
Unix has some great filesystem features.
DOS used to have some similarities, but ....
But where root is / in UNIX, the closest in DOS is C:\.
Where you can mount a physical drive in the logical tree of UNIX. You used to, but can't under DOS. So you have separate drive letters.
Perhaps you need to find something programmatically unique about the NAS drive to figure out its drive letter.
But I've been away from DOS (Windows ) for a while, perhaps there is other methods.

Meek Wriggle
Jul 5, 2009, 10:05 PM
Software on Windows is usually stored in the "C:\Program Files" directory these days. In fact, since Windows 95 programs are rarely installed in other folders. And yes, the C:\ is important as the others say; in Windows drives are designated by letters, for example, D:\ is usually the DVD/CD drive and A:\ is the floppy.

I'm the reverse as I spent 15 years using Windows (still do for work). I dabbled in Linux over the years (especially at University) so getting used the Unix filesystem was a big learning curve for me. Now I use Macs it makes a little more sense to me.

mongrol
Jul 5, 2009, 10:09 PM
Never use hard paths. Use environment variables to get the path instead. Theoretically you should never need to know the windows file structure. Here's the relevant ENV's

ProgramFiles=C:\Program Files
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\uxxxxxx\LOCALS~1\Temp
USERPROFILE=C:\Documents and Settings\uxxxxxx
windir=C:\WINDOWS

michaelbartnett
Jul 6, 2009, 01:52 AM
Hey there, I'm a relatively recent switcher from Windows--in searching for anyone encountering an Xcode bug I couldn't help but read this thread.

Basically, Windows will not even let most users look at the root drive C:\. Mongrol has the best solution with environment variables, but if you are forced to hard code it, then put your actual software in "C:\Program Files\<Application Name>" or "C:\Program Files\<Developer Name>\<Application Name>" if you're installing multiple packages or solutions. User data typically goes in either "C:\Documents and Settings\<username>\Application Data" or C:\Documents and Settings\All Users\Application Data" for global user data. But, a lot of software (especially older software) just sticks user data in Program Files along with the software itself.

If they run the uninstaller for your software, most files in Program Files will get deleted, but it will leave the user data alone (unless your installer can allow the user to specify user data removal). Theoretically, putting all user data in the appropriate user directory allows you to easily backup and restore or migrate user data. Special emphasis on "theoretically".

If you try to put anything other than shared DLLs and similar things in "C:\Windows" or any of its subdirectories, antivirus software, system admins, and some of your smarter users are going to have a cow.

mongrol
Jul 6, 2009, 06:03 PM
No no no. Never never never never hard code paths into installers. Let's say that again. Never never never never hard code paths into installers. The user might have Windows installed anywhere. D:, Z:, T:, They might not even have a C: drive at all and that will crash your program. Use ENV's only.

ClaudioFaria
Jul 15, 2009, 06:53 PM
I'm a Windows XP user.

Do not hard-code drive letters or path names. Not only a user may install Windows in a drive other than C:, as mongrol said; also path names change with "localization" (microsoft-speak for "translation into other languages"). So, in a Windows system in Portuguese, "C:\Program Files" becomes "C:\Arquivos de programas". Always use environment variables, which are parsed into actual names by enclosing their names in '%'.

%HomeDrive% is the drive where Windows was installed, usually C:.

%WinDir% is the folder where Windows was installed, usually %HomeDrive%\Windows. Do not place data under it.

%ProgramFiles% is where applications should install themselves to, along with data that's not user-specific (but not shortcuts -- see below). In English, it's usually %HomeDrive%\Program files. It's customary for application installation to create there a folder under it with the company's name, if it doesn't already exist, then a subfolder with the application name.

%UserName% and %UserDomain% are what their names say.

%UserProfile% is where data specific to a user is placed. In Windows XP, it's usually %HomeDrive%\Documents and Settings\%UserName%; it may be %HomeDrive%\Documents and Settings\%UserName%.%UserDomain% if the user belongs or has belonged to more than one domain. I believe that in Vista, or is it Windows 7, Microsoft has changed "Documents and Settings" to "Users" (shorter and no spaces, why didn't they think of it before?), but in XP the cumbersome name is enthroned.

I can't find the environment variables for %UserProfile% subfolders; they should follow their folder names in English, without spaces. The most important are:

"Application Data" -- that's where you put your data. Follow the convention of a folder with the company name, then a subfolder with the application name.

"Desktop" -- the icons (shortcuts) on the desktop.

"Start menu" -- the icons (shortcuts) you reach by clicking Start.

"My documents" -- the user's own data (leave alone).

To complicate matter a bit further, there's a pseudo-user called "All Users". The shortcuts in its Desktop and Start menu subfolders are added to the ones in the user's folders to make up what is actually presented via the Start button or on the desktop. If an application is meant to be used by all users, that's where shortcuts should be placed.

I hope that helps.