|
|
You're welcome!
|
|
|
|
|
I am writing an application that requests a file path from a user so that the application can process supported files in that directory. It is a console application. I would like to know how I can validate the path entered by the user to make sure that the path exists. I am programming in the C language. Please help.
|
|
|
|
|
|
Thanks Niklas, I believe this function will do, but it seem to be a Windows specific function. Do we have any way around in the ANSI C standard? If there isn't I will use the function you showed me, it's just that I want to keep the use of Windows functions at minimum in this application.
|
|
|
|
|
Maybe _stat() from <sys/stat.h> checking if the st_mode member of the _stat struct is _S_ISDIR. I don't know how much standard that is though.
|
|
|
|
|
I'm reading Dennis Ritchie's 'C programming language 2nd ed' and the part that I thought might be a solution is what you've directed me. Thanks very much.
|
|
|
|
|
Which file paths are valid or invalid is determined by the operating system, not the programming language. What is valid for Windows may not be valid for others such as Unix, and vice versa.
If portability of your code is of prime importance, your best bet IMO would be to actually try and use the path, say by attempting to create a file in the given directory path.
When I create portable code, I define my own little virtual OS and have an OS.h file which has different sections for each of the platforms (operating system and compiler tools) I support; it is full of defines from my virtual OS to the actual one.
|
|
|
|
|
Being a bit academic, you are not always able to create a file in a directory, but for other reasons.
Edit: Think I need some sleep.
|
|
|
|
|
I agree attempting an operation isn't the ideal way to determine validity, however it may (or may not) come pretty close to what the OP wants, after all the user entered a path for some reason, so maybe trying whatever it is the app is supposed to do with the path right away is a good enough approach, and by definition it would be as portable as the rest of the app.
|
|
|
|
|
in addition to the help from Luc & Niklas, there are things like Apache APR http://apr.apache.org/[^] which may be of use if you are doing a lot of this. I like Luc's approach for small time - which is essentially the same, but just defining the functions you need, whereas APR is a bit more encompassing
'g'
|
|
|
|
|
There's also _access() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi all
In CTree control according to MSDN i try to insert image of Recycle bin.But how can i get Int Imge number of Recycle bin?
m_tree..InsertItem("Recycle bin",int Image,hRoot);
I try to find int Image number.
Help me
|
|
|
|
|
One way, albeit antiquated, would be to look in your C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Win95 folder.
A better solution would probably be to use SHGetFolderLocation(CSIDL_BITBUCKET) and SHGetFileInfo(SHGFI_PIDL | SHGFI_ICON) .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
The int is an index into the associated CImageList[^]. That in turn has to be created by you, and you can add resource items or load items from other sources at runtime. There are no predefined images for the CTreeCtrl .
|
|
|
|
|
If you're looking to get the icon that belongs to the recycle bin you can use SHGetStockIconInfo API.
This will work only on Windows Vista and above.
To support earlier OS versions you must use the SHGetFolderLocation and SHGetFileInfo APIs.
|
|
|
|
|
CreateFile function is fail to create a file on windows 7 (login user has administrative right)
Createfile also fail to open any drive
any solution for that
|
|
|
|
|
MKC002 wrote: any solution for that
Check GetLastError() .
Also, turn UAC off and see what that does.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
If you're creating the file in any of the locations not recommended like C:\ , C:\Windows etc. your program will need to run with elevated privileges. Try executing the program elevated by right clicking and selecting Run as administrator .
|
|
|
|
|
i run my program as administrator (right click on exe and select run as administrator).but still it fails to creat file
how to programatically run my program as administrator?
i think there is UAC problem but i dont know how to solve it
|
|
|
|
|
We are upgrading to VS2010 (C++) and on XP machines it is dog slow. Sometimes the IDE will hang the PC for 30 seconds or more. Right click a mouse button, and 30 seconds later the popup menu appears. And this is not while compiling. VS 2010 seems fine on Windows 7. Does anyone have any ideas what the problem is? I assume it is something like intellisense getting its knickers in a twist, or some other background task. Oddly enough the Task Manager shows near zero CPU usage during these hangs. We do have plenty of RAM so virtual memory paging is not thrashing.
|
|
|
|
|
You might also want to ask here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
|
Create mfc dialog base application and put an activex control on dialog (calender control or web browser control). Initialize activex control with some data
execute the application. activex control on Dialog box displays the data.
right click on activex control-> context menu appears
how to avoid this context menu and any other mouse/keyboard operations on activex control
|
|
|
|
|
check whether activex control exposes any functions to suppress menus.
If not, override PreTranslateMessage() function for your parent window, and simply do return for the messages that generates menus on ativex control
for eg, for Mouse right button click/double click:
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_RBUTTONDOWN || pMsg->message == WM_RBUTTONDBLCLK)
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}
you may do further filtering by checking pMsg->pt or pMsg->hwnd members also.
|
|
|
|