I'm writing a Windows program that needs to store some user files.
The logical place to store them is in "Application Data", right?
Is there a good way to find the correct location of that directory,
preferably without any C extensions? It's ok if the directory is
found at installation time rather than runtime, and bdist_wininst does
have a way to find it from a post-installation script. The trouble is
that the post-installation script doesn't seem to have an obvious way
to communicate the info to the application for later use!
Any suggestions?
Thanks. 7 11798
[Paul Rubin wrote] I'm writing a Windows program that needs to store some user files.
The logical place to store them is in "Application Data", right?
Is there a good way to find the correct location of that directory, preferably without any C extensions? It's ok if the directory is found at installation time rather than runtime, and bdist_wininst does have a way to find it from a post-installation script. The trouble is that the post-installation script doesn't seem to have an obvious way to communicate the info to the application for later use!
Any suggestions?
The canonical way is using the Window API SHGetFolderPath function with
the CSIDL_APPDATA key:
from win32com.shell import shellcon, shell
print shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
This requires the PyWin32 extensions (which you already have if you have
ActivePython installed).
Alternatively you could write your own little C extension to call this
Window API function... but you didn't want to do that. You can also call
this WIndows API function (in the shell32.dll) with the Python "ctypes"
modules out there.
Trent
--
Trent Mick Tr****@ActiveState.com
You have the environment variable APPDATA. You can access it with
os.environ().
"Rune Strand" <ru*********@gmail.com> writes: You have the environment variable APPDATA. You can access it with os.environ().
Thanks!!!!!! Wow, I'd been hacking away at much messier approaches
than that. It's actually os.environ['APPDATA'] ;-)
I had a post yesterday on just that. Anyways, I always love it when
what can be a really annoying problem, reduces into as something simple
and elegant like a python dict. (in general, I find dictionaries
rock).
I remember a similar eureka, when some time ago I found it really neat
that split w/no args works on whitespace words. Or, things like min and
sort actually travel down levels of data structures for you. Or, when
one realizes things like "in" works on all sorts of sequences even
filehandes, or you can treat gzipped files just like normal files, or
coolness of cStringIO, or startswith and endsmith methods on strings,
or . . .
Hmm, I wonder if there is a page of the little python coolnesses. I
recall one of python annoyances.
john
[Paul Rubin wrote] "Rune Strand" <ru*********@gmail.com> writes: You have the environment variable APPDATA. You can access it with os.environ().
Thanks!!!!!! Wow, I'd been hacking away at much messier approaches than that. It's actually os.environ['APPDATA'] ;-)
Note that the APPDATA environment variable is only there on *some* of
the Windows flavours. It is there on Win2k and WinXP. It is not there on
WinME. Dunno about Win95, Win98, WinNT... but you may not care about
those old guys.
Cheers,
Trent
--
Trent Mick Tr****@ActiveState.com
Trent Mick ha scritto: Note that the APPDATA environment variable is only there on *some* of the Windows flavours. It is there on Win2k and WinXP. It is not there on WinME. Dunno about Win95, Win98, WinNT... but you may not care about those old guys.
That's (I guess) because the DOS spawn (win9x family) was single user
and did not really have concepts like home directories, profiles,
separate settings for each user... hell, it did not even have users! :-D
--
Renato
--------------------------------
Usi Fedora? Fai un salto da noi: http://www.fedoraitalia.org
On 28 Jun 2005 21:09:12 -0700, Paul Rubin <http://ph****@NOSPAM.invalid> wrote: "Rune Strand" <ru*********@gmail.com> writes: You have the environment variable APPDATA. You can access it with os.environ().
Thanks!!!!!! Wow, I'd been hacking away at much messier approaches than that. It's actually os.environ['APPDATA'] ;-)
Hm, which windows is that? Not NT4 ;-)
Regards,
Bengt Richter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JohnD |
last post by:
I am using XP Pro and when I try and run an ASP.NET page on my own server I recieve the following error messag
Server cannot access application directory ..(web directory here)... The directory...
|
by: 21novembre |
last post by:
Hi all,
I made a question several days before to describe my strange trouble of
mysqldump. But I still can't figour it out. Well, I just want to ask
another question whether I could just backup...
|
by: Rajat Tandon |
last post by:
Hello Everybody,
Please guide me so that I can fulfill this challenging assisnment ...
I have been asked to "Restructure a Windows application" from scratch in 2
months. The existing...
|
by: z. f. |
last post by:
Hi,
I'm working on a web project and i create classes to do business logic and
connect to DB.
i also need a windows application to do the same functionality as defined
in classes inside the...
|
by: Alex Maghen |
last post by:
Hi. I had previously installed VS2005 beta 1. I carefully followed all the
steps (I thought) to deinstall it and then installed beta 2. According to the
documentation, the "Data" directory which...
| |
by: Simon Verona |
last post by:
I have a windows forms application that I wish to build an installer for.
Part of this application is an .asp webpage that I wish to install alongside
the windows application and create a virtual...
|
by: MrSpock |
last post by:
1. Create a new Windows Application project.
2. Open the project properties and check "Make single instance application".
3. Build.
4. Go to the release folder and run the application.
5. Try to...
|
by: Matthias Wohlmann |
last post by:
Hi,
I'm getting the following error when trying to start my application
using Internet Explorer:
"Server cannot access application directory D:\xxx. The directory does
not exist or is not...
|
by: Chad A. Beckner |
last post by:
Hi everyone,
I have a common class library (call it common_library) that I
include/reference in my projects. In this class library, I would like to
have it save certain settings to the...
|
by: ilangovan |
last post by:
Hai friends,
I have a problem in my windows application which contains about 11000
lines. For this application, i download the tabcontrols from the net. An error which has the name of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |