Answered by:
What are Windows runtime API's equivalents of _chdir, _getcwd, and GetEnvironmentVariable

Question
-
After I enable Windows Store app support to my project (in "Configuration Properties, General, Windows Store app support"), VS2012 compiler seems to do an extra work to check if my function calls are supported by Windows runtime API. Now these three functions are picked out: _chdir, _getcwd, and GetEnvironmentVariable. So What are Windows runtime API's equivalents of these functions?Saturday, August 25, 2012 1:36 PM
Answers
-
Like Sheng Jiang says, apps have direct access only to their install directory and application data directories. Because the C and C++ file API directly access the target files they can be used only for those directories.
Your app can get brokered access to other directories (e.g. libraries declared with capabilities, user selected folders via the FolderPicker) through StorageFile and StorageFolder objects. When you use these, the broker process does the actual file access on your behalf. The data within the file is provided to the app via a stream returned from StorageFile::OpenAsync.
See Accessing data and files for more information.
--Rob
- Marked as answer by Leonard Monday, August 27, 2012 9:41 AM
Monday, August 27, 2012 6:17 AMModerator
All replies
-
Metro style apps don't have access to environment variables.
As for current directory functions, why do you need them in a Windows application? A simple open file dialog call could change the current directory to somewhere else.
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- Edited by Sheng Jiang 蒋晟 Saturday, August 25, 2012 3:11 PM
Saturday, August 25, 2012 3:10 PM -
Hi Sheng, thanks for your response.
I need to traverse all files in the given directories specified by the user. Once the user specifies the files in different directories (e.g. C:\dir1\1.txt and D:\dir2\2.txt), she ask my app to print out the information of related files (e.g. the file next to C:\dir1\1.txt, and the last file in the directory where D:\dir2\2.txt resides). So I need to change the current directory without presenting users with open file dialog.
Saturday, August 25, 2012 4:28 PM -
The way to read the given directory out of a selected file path is to use PathRemoveFileSpec or something like that to remove the file name and back slash.
For metro apps you don't have access to folders outside your install directory, except those added to a library that you have permission to.
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- Edited by Sheng Jiang 蒋晟 Saturday, August 25, 2012 5:20 PM
Saturday, August 25, 2012 5:19 PM -
Are you sure that a metro app cannot access folders outside its installation directory, at least a read-only access? This restriction will make most of metro apps useless! Think of an image editing app cannot access a user's photo album. If that's true, then Windows RT will be another Windows Phone 7 with DOA.Sunday, August 26, 2012 1:11 AM
-
There are other ways to open files without permission, but require the users to pick the files to be opened.
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVPSunday, August 26, 2012 3:59 AM -
Like Sheng Jiang says, apps have direct access only to their install directory and application data directories. Because the C and C++ file API directly access the target files they can be used only for those directories.
Your app can get brokered access to other directories (e.g. libraries declared with capabilities, user selected folders via the FolderPicker) through StorageFile and StorageFolder objects. When you use these, the broker process does the actual file access on your behalf. The data within the file is provided to the app via a stream returned from StorageFile::OpenAsync.
See Accessing data and files for more information.
--Rob
- Marked as answer by Leonard Monday, August 27, 2012 9:41 AM
Monday, August 27, 2012 6:17 AMModerator -
Thanks Rob.Monday, August 27, 2012 9:41 AM