|
ShFileOperation (or IFileOperation ) is your friend.
look at the documentation on MSDN.
Watched code never compiles.
|
|
|
|
|
Hi,
thanx for answer!
Arrin!
|
|
|
|
|
Hi,
i forgot to say that this is a directory in a LAN?
In this case, do i have to do the same, to use same function SHFileOperation for network operations???
When i tray to do this, i receive an error like this "Invalid File path"??
Thanks
Arrin
|
|
|
|
|
Beware to string escapes: LAN names like \\server\share\dir\file.ext should be "\\\\server\\share\\dir\\file.ext".
It is one of the most common errors.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Hi,
thanks for answer, is that ah way to resolve a network drive to this LAN name?
My Letter is this one P on network, "P:\project\projectname.pf" how to resolve this name to "\\server\project\"??? Is there any solution for this??
I select this folder over an File Dialog, and they give me this path back, but how to convert him to this LAN name!
Thanks for any help!
Arrin
|
|
|
|
|
Hi,
when i try to use ShFileOperation i receive a error like "Folder is open by another application"???
My only problem that this dont work on LAN, over LAN!
In a local drive its all ok!
Arrin
|
|
|
|
|
An alternative to SHFileOperation is using MoveFile[^] or MoveFileEx[^] APIs. These functions can rename either a file or a directory.
|
|
|
|
|
Hi,
thanx for answer!
Arrin!
|
|
|
|
|
Try
MoveFile(LPCTSTR currentNameOfFolder,LPCTSTR newNameOfFolder);
Example:
MoveFile(_T("D:\\TestFolder\\RenameMe"),_T("D:\\TestFolder\\MyNewName"));
|
|
|
|
|
i am creating a function IsFolderExists(LPTSTR str)
str = "C:\New Folder"; //It Fails to get the Window Folder
but when i
str = "C:\\New Folder"; //It gets the Windows Folder
am i doing wrong, or \\ is required. If required then how to build a path
Example : C:\New Folder into C:\\New Folder. Help.....
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
IsFolderExists(lpCmdLine)
return TRUE;
}
void IsFolderExists(LPTSTR str)
{
WIN32_FIND_DATA wfd;
HANDLE hFile;
hFile = FindFirstFile(str,&wfd);
if ( hFile != INVALID_HANDLE_VALUE )
{
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)!=0)
MessageBox(NULL,_T("Is Directory"),_T(""),MB_OK);
else
MessageBox(NULL,_T("Is File"),_T(""),MB_OK);
}
else
{
MessageBox(NULL,_T("Neither File or Folder"),_T(""),MB_OK);
}
}
When i drag a folder [ NewFolder] on myapp.exe it works but
when i drag a folder having space [ New Folder ] it doesn't work.
please help...
Some Day I Will Prove MySelf :: GOLD
modified on Saturday, January 22, 2011 12:42 AM
|
|
|
|
|
The "\" is known as the (or one of?) "escape" character.
that means that if you want to put a tab, for example in a string you would put "\t" to indicate a tablature; that means that the string will look at the "\" and the next character after that and see a "t" and will understand it as a "tablature" (same thing for quotes and double quotes)
so, in general, when a string (CString) encounters a "\" in a string it will check the next character and see if it means something.
the question is how can I put a literal "\" in string without being recognize as an escape character ?
the anwser is to double the "\" ...
str = "C:\\Windows";
When hard-coding paths in string one should always put "\\", but, for example, if you have a UI with an edit box to type in the path, you don't need to use the "\\" you can just use the "\".
Watched code never compiles.
|
|
|
|
|
Of course '\' is the only C/C++ escape character for literal strings.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
IsFolderExists(lpCmdLine)
return TRUE;
}
void IsFolderExists(LPTSTR str)
{
WIN32_FIND_DATA wfd;
HANDLE hFile;
hFile = FindFirstFile(str,&wfd);
if ( hFile != INVALID_HANDLE_VALUE )
{
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)!=0)
MessageBox(NULL,_T("Is Directory"),_T(""),MB_OK);
else
MessageBox(NULL,_T("Is File"),_T(""),MB_OK);
}
else
{
MessageBox(NULL,_T("Neither File or Folder"),_T(""),MB_OK);
}
}
When i pass the Folder name from command line like,
myapp.exe C:\Windows -result is neither file or folder but when used as
myapp.exe C:\\Windows -result is Is Directory.
How to solve this. Help.
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
You should also print out the contents of wfd.cFileName to see exactly which file or directory you are displaying attributes for.
I must get a clever new signature for 2011.
|
|
|
|
|
how can I put a literal "\" in
string without being recognize as an escape
character ?
the anwser is to double the "\" ...
s t r = " C : \ \ W i n d o w s " ;
i agree with you. But i want to do it programatically. I want to replace \ with ''\\''. Please help
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
The '\\' notation is only needed for the compiler. It isn't needed in the runtime. (when you select a file from the open file dialog, the path is returned as "C:\New Folder"
If you want to replace them for other reasons, then use 4 '\'. i.e. to specify a SMB server, you would use CString strServer = "\\\\server_name\\folder"; .
To replace it you just need a replace function. If you are using something liks CString , it as a Replace() method.
CString strName = "\\hello";
strName.Replace("\\", "\\\\");
|
|
|
|
|
Thanx a lot.
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
|
You already got answers the last time you posted, what's wrong with them ?
Please, read the posting guidelines at the top of this forum before posting the next time.
|
|
|
|
|
Hello guys!
I have to connect to WebDAV Server, example: http://webdav.pspace.co.kr
But I cannot find any code example for DavAddConnection Function.
And, in MSDN I found this:
"Use this function when you are connecting to a WebDAV server using the Secure Sockets Layer (SSL) protocol and therefore must specify a certificate. To connect to a WebDAV server without specifying a certificate, use a Windows networking function such as WNetAddConnection2 or WNetAddConnection3."
Does anyone know some examples of DavAddConnection?
Found some code examples for WNetAddConnection2 and tried to connect, but, unsuccessfully.
CString passW=_T("pwd123");
CString userN=_T("user1");
CString locname=_T("webdav.pspace.co.kr");
DWORD dwRetVal;
NETRESOURCE nr;
DWORD dwFlags;
memset(&nr, 0, sizeof (NETRESOURCE));
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = (LPTSTR)((LPCTSTR)locname);
nr.lpRemoteName = (LPTSTR)((LPCTSTR)locname);
nr.lpProvider = NULL;
dwFlags = CONNECT_UPDATE_PROFILE;
dwRetVal = WNetAddConnection2(&nr, passW, userN, FALSE);
if (dwRetVal == NO_ERROR)
AfxMessageBox(_T("Connection added to"));
else
AfxMessageBox(_T("Error"));
I'm getting "Error".
By the way, I'm I doing right trying to connect to WebDAV server via this technic?
Thank you.
modified on Thursday, January 20, 2011 8:30 PM
|
|
|
|
|
Use this to see what error you are getting. That may shed some light on what may be causing it
if (dwRetVal == NO_ERROR)
AfxMessageBox(_T("Connection added to"));
else {
TCHAR szError[32];
_stprintf(szError, _T("Error %u"), dwRetVal);
AfxMessageBox(szError);
}
|
|
|
|
|
Thanks for the reply.
I'm getting "Error 487".
|
|
|
|
|
MSDN[^] says
Error Name: ERROR_INVALID_ADDRESS
Error Code: 487 (0x1E7)
Error Text: Attempt to access invalid address.
|
|
|
|
|
Check out your last parameter in WNetAddConnection2(&nr, passW, userN, FALSE);
According to MSDN[^] 0 is not a legal value for the parameter dwFlags and FALSE is #define FALSE 0 .
Did you mean to pass in your variable dwFlags ? (in the sample on MSDN they do)
|
|
|
|
|
Hello.
I have tried a couple of thing to make the code work. But, still, I cannot connect to our WebDAV server "webdav.pspace.co.kr".
But, using the code shown below, I'm getting a positive answer: "Connection added to":
CString locname=_T("\\\\www.barracudaserver.com\\dav\\");
DWORD dwRetVal;
NETRESOURCE nr;
DWORD dwFlags;
memset(&nr, 0, sizeof (NETRESOURCE));
nr.dwScope=RESOURCE_GLOBALNET;
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = NULL;
nr.lpRemoteName = (LPTSTR)((LPCTSTR)locname);
nr.lpProvider = _T("");
dwFlags = CONNECT_UPDATE_PROFILE;
dwRetVal = WNetAddConnection2(&nr, _T(""), _T(""), dwFlags);
if (dwRetVal == NO_ERROR)
{
AfxMessageBox(_T("Connection added to"));
}
else
{
TCHAR szError[32];
_stprintf(szError, _T("Error %u"), dwRetVal);
AfxMessageBox(szError);
}
In the case of locname=_T("\\\\webdav.pspace.co.kr\\") the result is "Error 53:", which means "The network path you specified is not found."
May be something is wrong with the server or may be I'm using the wrong approach.
Any ideas?.. 
|
|
|
|
|