473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

os.path.expanduser('~/foo') and MSWindows "My Documents"

On *nix, ~/foo refers to a file in a user's home directory. On
MSWindows, users normally look at "My Documents" in their home
directory. ISTM that a file that my program would put in ~/. on Linux
should be put in "~/My Documents/" (modulo os.path.normpath()) on
MSWindows, where a user would expect it. How do you guys cope with this
issue?
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 22 '05 #1
8 2252
Try this:
from win32com.shell import shell, shellcon
HOMEDIR = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_PERSONAL)
myfile_location = os.path.join(HOMEDIR, myfile_name)

Define a HOMEDIR for your various platforms (use sys.platform to figure
out what choice to make) and the rest of your code should not need to
care where "home" is...

Regards,

jim

Nov 22 '05 #2
Try this:
from win32com.shell import shell, shellcon
HOMEDIR = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_PERSONAL)
myfile_location = os.path.join(HOMEDIR, myfile_name)

Define a HOMEDIR for your various platforms (use sys.platform to figure
out what choice to make) and the rest of your code should not need to
care where "home" is...

Regards,

jim

Nov 22 '05 #3
In article <11**********************@o13g2000cwo.googlegroups .com>,
ji*******@gmail.com wrote:
Try this:
from win32com.shell import shell, shellcon
HOMEDIR = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_PERSONAL)
myfile_location = os.path.join(HOMEDIR, myfile_name)

Define a HOMEDIR for your various platforms (use sys.platform to figure
out what choice to make) and the rest of your code should not need to
care where "home" is...


Sounds good, thanks. I'll read up on it all tomorrow.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 22 '05 #4
In article <11**********************@o13g2000cwo.googlegroups .com>,
ji*******@gmail.com wrote:
Try this:
from win32com.shell import shell, shellcon
HOMEDIR = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_PERSONAL)
myfile_location = os.path.join(HOMEDIR, myfile_name)

Define a HOMEDIR for your various platforms (use sys.platform to figure
out what choice to make) and the rest of your code should not need to
care where "home" is...


Sounds good, thanks. I'll read up on it all tomorrow.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 22 '05 #5
python
import os
help(os.path.expanduser)
import platform
platform.system() 'Windows' platform.release() 'XP'


:-)

Dalius

Nov 22 '05 #6
python
import os
help(os.path.expanduser)
import platform
platform.system() 'Windows' platform.release() 'XP'


:-)

Dalius

Nov 22 '05 #7
In article <11**********************@g44g2000cwa.googlegroups .com>,
da*****************@gmail.com wrote:
python
import os
help(os.path.expanduser)
import platform
platform.system() 'Windows' platform.release() 'XP'


platform looks good.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 22 '05 #8
In article <11**********************@g44g2000cwa.googlegroups .com>,
da*****************@gmail.com wrote:
python
import os
help(os.path.expanduser)
import platform
platform.system() 'Windows' platform.release() 'XP'


platform looks good.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 22 '05 #9

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

Similar topics

0
by: Grant_S | last post by:
I need to identify the path to a users "My Document" folder where the user has a roaming profile and their "My Documents" folder is mapped to a network share as the H drive (specifically H:\\ -...
2
by: Karl Koscher | last post by:
I'm trying to communicate with a USB device using C#. I'm able to determine the device path using P/Invoke and SetupDiGetClassDevs, SetupDiEnumDeviceInterfaces, and SetupDiGetDeviceInterfaceDetail,...
6
by: JuLiE Dxer | last post by:
Is there a way via C# to programmatically retrieve the full path name to folders like "My Documents" ?? I'm seeing examples with the use of Shell32 stuff I believe, SHGetSpecialFolderLocation...
10
by: Alpha | last post by:
I use FolderBrowserDlg for user to select a folder path then store it in the sql table. I then retrieve it to concatenate in a sqlcommand text to retrive files from that directory but it won't...
5
by: Tom Vogel | last post by:
Creating a subfolder within my ASP.NET application folder fails with the above error, but only at my hosting provider. The command: Directory.CreateDirectory(path) Path is set to...
1
by: Jonas Auken | last post by:
hi, I have a repeater which dynamically loads another usercontrol throught databinding: OnClick: DataBind() rptProduct_ItemDataBound: ViewSmall _viewSmall = (ViewSmall)...
9
by: Clinton Frankland | last post by:
Hi, On a Windows 2000 Server when attempting to use System.IO.Directory.CreateDirectory(string.concat(Server.MapPath(""), "\verify")) I receive a System.IO.DirectoryNotFoundException error:...
4
by: Ben | last post by:
Hello, I need to save some information into a text file. For this, I use : FileOpen(1, "c:\MyFile.txt", OpenMode.Output) For I = 0 To iCpt - 1 WriteLine(1,...
0
by: Tony Nelson | last post by:
On *nix, ~/foo refers to a file in a user's home directory. On MSWindows, users normally look at "My Documents" in their home directory. ISTM that a file that my program would put in ~/. on Linux...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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...

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.