473,381 Members | 1,450 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,381 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 2251
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.