473,513 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find Windows "Application data" directory??

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.
Jul 19 '05 #1
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
Jul 19 '05 #2
You have the environment variable APPDATA. You can access it with
os.environ().

Jul 19 '05 #3
"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'] ;-)
Jul 19 '05 #4
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

Jul 19 '05 #5
[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
Jul 19 '05 #6
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
Jul 19 '05 #7
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
Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2142
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...
3
4681
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...
5
1980
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...
5
1563
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...
7
2636
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...
0
1032
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...
9
5101
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...
2
3080
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...
0
1329
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...
0
1389
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...
0
7171
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...
0
7388
Oralloy
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,...
0
7547
jinu1996
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...
1
7114
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...
0
7541
tracyyun
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...
0
5693
agi2029
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,...
0
4751
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...
0
1607
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 ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.