Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy File To My Documents Folder

Status
Not open for further replies.

mark1110

Programmer
Apr 20, 2005
85
US
Hi,

I have an old VFP 6 application that uses a select into statement to copy a file to a users root directory.

SELECT *
FROM address
INTO c:\address

I now need to copy that file to the users my documents directory. I have 30 users with different my document directory names. Is there a simple way to find out what the my document directory name is so I could copy the file to it?

Thanks,

Mark
 
Yes, Mark, there is: GETENV("USERPROFILE"). You might want to try

COPY FILE (MyFile) TO (ADDBS(GETENV("USERPROFILE")) + "My Documents\" + MyFile)

HTH.


Regards,

Ilya
 
Beware of localized Windows Versions. Since Vista the folders are indeed all named englisch and only shown in localized names, but up to XP they are language specific.

Also, if you plan to copy files to many users documents folders it's not that easy. First there are restrictions only an Admin user could copy to many not logged in users. And second that would only make sense for local profiles, if profiles are server stored documents would need to go to the server stored profile unless a user is logged in.

If that is what you intend a Mail attachment would be the better working solution.

Bye, Olaf.
 
Here's a function that will return the path to MyDocuments, or its equavalent under Vista or Windows 7, in all localisations of Windows:

Code:
FUNCTION GetPersonalFolder

* Returns the path to the My Documents or similar folder on the user's system;
* this is usually C:\Documents and Settings\username\My Documents in XP, and
* C:\Users\username\Documents in Vista

LOCAL lcPath, lnPidl, lnPidlFound, lnFolderFound  

* Delcare the API functions
DECLARE LONG SHGetSpecialFolderLocation IN shell32 LONG HWND, LONG nFolder, ;
  LONG @ ppidl
DECLARE LONG SHGetPathFromIDList IN shell32 LONG Pidl, STRING @ pszPath
DECLARE CoTaskMemFree IN ole32 LONG pvoid

lcPath = SPACE(260)
lnPidl = 0

* Get the path
lnPidlFound = SHGetSpecialFolderLocation(0, 0x05, @lnPidl)
                && 0x05 in the above means "My Documents")
IF lnPidlFound = 0
  lnFolderFound = SHGetPathFromIDList(lnPidl, @lcPath)
  IF lnFolderFound = 1
    * Success
    lcPath = LEFT(lcPath, AT(CHR(0), lcPath) - 1)
    ENDIF 
ENDIF 
CoTaskMemFree(lnPidl)
lcPath = ALLTRIM(lcPath)

* Release the APIs
CLEAR DLLS "SHGetSpecialFolderLocation", "SHGetPathFromIDList", "CoTaskMemFree"

RETURN lcPath

I based this on a larger function that was published by Doug Hennig. Doug's function also returned other special folders; mine just returns My Documents, etc.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top