cross platform reference to specific drive/directory - file

Is there a way to express a specific drive in both windows/linux? Windows usually uses"D:\etc" and Ubuntu/etc uses something like "/media/user/drive_name". Is there a awy to just refer to something like "/dev/sdc1" which both Windows and Ubuntu will recognize as the same drive?
I am trying to put this in a config file for a python program which can be run on an external data drive from an internal drive containing multiple OSs. The program has to refer to a separate external data drive, but I would like the program to work the same way for all of the OSs.
Is this possible?

Either you just need to account for your OS type in each machines properties file or test for the OS in the code and act accordingly.
import os
if os.name == "windows"
path = "D:/windows/path"
elif
path = "/unix/path"

Related

PortableApps-style registry call redirection to config file

I like the idea of Windows applications that run regardless of which folder they are in and which don't use the registry for settings but use local files instead.
This allows such applications to be stored on any disk or even a USB drive, which can be used on different computers while behaving the same way. That's the basic principle of PortableApps.
An additional bonus is that no administrator rights are needed for the installation, since there is no installer.
However existing applications are often already written to use the registry.
Is there a C library that can be used to build these applications from (C/C++) source code with minimal changes which redirects all registry access (read and write) for at least the application's settings to a file on disk (relative to the running application or library)?
I guess it shouldn't be that hard using #define to redefine all Windows API calls to registry functions.
Then it would just be a matter of the right #include in the right place and linking to an additional library.

File system in Toit

Judging by the lib_v1.0.2 library, access to the file system is implemented in Toit. May be can give some simple examples, which would include:
Create a file,
Writing data to file,
Reading data from a file,
Deleting a file,
Is there support for folders, and if so, what is the nesting level and how to get a list of files in the folder?
Update 2022-12-20: the host package's filesystem functionality (host.file and host.directory) is now supported for sdcards.
The filesystem libraries are not supported on ESP32 devices. They were implemented for host machines (like Linux), but that version isn't released.
The libraries will likely move soon and then not be accessible anymore.
If you want to store data on the device, maybe the device flashstore works for you:
import device
main:
store := device.FlashStore
store.set "key" "data"

Finding file locations in offline softwares in C

At some point in my C program I have to deal with something like this.
FILE * fptr = fopen("/Parent/child/.../file.dat");
Which means in order to access any file I need to know it's location. That's all understandable.
But, how can I make this generic? In my computer "/Parent/child/.../file.dat" will work because that's where the file is stored, but I'm making a software to distribute to other users so the path obviously differs. My question is, how can I install a specific file into the user's computer such that I can know and get the location of that file. I a but confused about this concept so any resources that could help me understand it better would be greatly appreciated.
In Linux the default path to application files should be hardcoded. There is a standard which applications should follow. For example, architecture-independent files should go to /usr/share/ and then either your application name or, if you expect the data to be shared between applications, a generic category such as images. User-specific configuration files should go $HOME/.config/<app-name>. Older applications place their default configuration in $HOME/.<app-name> instead.
You should also provide an ability to override the default path to the data with a command line switch and/or an environment variable and/or a user configuration file (the location of the latter should also be overridable with a command line switch and/or an environment variable).
Some applications search for their data directory relatively to the executable position. An executable can know its own absolute path by reading /proc/self/exe symbolic link. For example, if an executable finds itself in /usr/local/bin/somename, it can look for /usr/local/share/<app-name> (two levels up from the executable name and down to share/<app-name>.).
Finally, if you distribute source code for the users to build, the file locations should be configuration parameters.

Directory path which does not physically exist on my device

I am learning Python programming language. Currently
I am experimenting i-o files. I imported sys module and
in sys.path list I saw two kinds of paths:
/data/data/org.qpython.qpy3....
/storage/sdcard0/qpthon...
The former path does not exist physically on my device
(Tablet), although I can create/read files using this
path through python.
I want to know about these paths.
What are they called?
What are they for? etc.
The first path, /data/data/org.qpython.qpy3, this is where the actual QPython app is stored on your device. I don't believe you can access this path without having root access.
The second path, /storage/sdcard0/qpthon, this is where QPython saves files by default. It uses this location because it can be easily accessed with normal user privileges.

Environment.SpecialFolders in Silverlight 4 on Mac

Silverlight 4 running with elevated permissions provides access to certain special folders in the file system.
http://msdn.microsoft.com/en-us/library/system.environment.specialfolder(VS.95).aspx
These work great on Windows, but what do they map to on Mac OSX systems?
My application needs to access "My Documents". Will this map somewhere sensible on the mac?
Yes, but with a little trick.
You can create a file on windows even the containing folder does not exist, but on OS X your have to create the directory first. If not you will get an exception.
My code is as follow:
Directory.CreateDirectory(dirPath); // Not necessary on windows
FileStream newFs = File.Create(dirFile);
newFs.Close();
newFs.Dispose();
On OS X the "My Documents" folder is here:
/Users/[UserName]/Documents

Resources