Is similar solution for PocketPC/WindowsMobile (but not based on CF .Net)?
ReplyI'm Can't change file name
void ThreadRoute1( void* arg )
{
USES_CONVERSION;
TCHAR szDir[MAX_PATH];
GetCurrentDirectory(sizeof(szDir)/sizeof(TCHAR),szDir);
HANDLE hDir = CreateFile( CString(szDir), // pointer to the file name
FILE_LIST_DIRECTORY, // access (read/write) mode
FILE_SHARE_READ|FILE_SHARE_DELETE, // share mode NULL, // security descriptor
OPEN_EXISTING, // how to create
FILE_FLAG_BACKUP_SEMANTICS, // file attributes
NULL // file with attributes to copy
);
Should change to
void ThreadRoute1( void* arg )
{
USES_CONVERSION;
TCHAR szDir[MAX_PATH];
GetCurrentDirectory(sizeof(szDir)/sizeof(TCHAR),szDir);
HANDLE hDir = CreateFile( CString(szDir), // pointer to the file name
FILE_LIST_DIRECTORY, // access (read/write) mode
FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_SHARE_DELETE, // share mode //add by xiaobb
NULL, // security descriptor
OPEN_EXISTING, // how to create
FILE_FLAG_BACKUP_SEMANTICS, // file attributes
NULL // file with attributes to copy
);
Reply
I need a sample code for setting a password for accessing a folder & it contined subfolders/files plz help me
ReplyHere we are getting notification message after the event happence like after file deletion, but how to get an event before deletion...
Replyhow can i get the last filename after rename? when i rename the folder,like "AAA" to "BBB" but i can only get the filename from Buffer[i] is "AAA" why?
Replyhow can i get the last filename after rename? when i rename the folder,like "AAA" to "BBB" but i can only get the filename from Buffer[i] is "AAA" why?
ReplyThe following segment of code is invalid. I used this snippet of code in my application and it took quite some time to track down the defect. I have found other samples on the net that use they same method, they are also incorrect.
do
{
m_Sec.Lock();
int item = pList1->InsertItem(pList1->GetItemCount(), CString(Buffer[i].FileName).Left(Buffer[i].FileNameLength / 2) + " - " + helper_txt );
pList1->SetItemText(item, 1, tm.Format("%Y/%m/%d/ - %H:%M:%S"));
i++;
m_Sec.Unlock();
}
while (!Buffer[i].NextEntryOffset);
In the loop, Buffer[i] is accessed. This is only valid for the first record returned (and yes, multiple records are returned sometimes).
The list of file notification records cannot be accessed as an array, you should use a pointer instead. When advancing to the next record, you need to add pBuffer->NextEntryOffset to the pointer to access the next record.
See the definition of:
typedef struct _FILE_NOTIFY_INFORMATION {
DWORD NextEntryOffset;
DWORD Action;
DWORD FileNameLength;
WCHAR FileName[1];
} FILE_NOTIFY_INFORMATION;
Also note that the string returned is not null terminated. The file length is returned in bytes, not character counts. You should perform a wide character string copy as follows:
wchar_t WideStringFileName[MAX_STRING_LENGTH * sizeof(wchar_t)];
// The filenames returned are not null terminated. Copy the characters and null terminate the string.
if (pBuffer->FileNameLength < sizeof(WideStringFileName)) {
// Copy the filename.
wcsncpy(WideStringFileName,pBuffer->FileName,pBuffer->FileNameLength/sizeof(wchar_t));
// Null Terminate the string.
WideStringFileName[pBuffer->FileNameLength/sizeof(wchar_t)]=L'\0';
}
else
WideStringFileName[0]=L'\0';
---
Reply
What results this "bug"?
Good Code, but it could be a good thing to update it . I had the same prb than leaflau...
ReplyThank you too for the good question.
ReplyI'm sorry for my mistake.I missed out another thread in my program. Thanks.
ReplyYou wrote:
for example, a new file was created in the folder i spying. I found this event, but unable to rename the file anyway now. Just have a try!
Solution:
Just use FILE_SHARE_READ|FILE_SHARE_DELETE|FILE_SHARE_WRITE
instead FILE_SHARE_READ|FILE_SHARE_DELETE to solve it.
Assume that your program is running and spying the folder "c:\Program Files" all along. And now, create a new file in this folder, not through your program, but windows Explorer, then try to rename it. No problem?
ReplyPlease pay attention on the following code fragment:
HANDLE hDir = CreateFile( CString("c:\\Program Files"), // pointer to the file name
FILE_LIST_DIRECTORY,// access (read/write) mode
FILE_SHARE_READ|FILE_SHARE_DELETE, // share mode
NULL,// security descriptor
OPEN_EXISTING,// how to create
FILE_FLAG_BACKUP_SEMANTICS,// file attributes
NULL // file with attributes to copy
);
in the demo project I was specify only FILE_SHARE_READ|FILE_SHARE_DELETE
To solve this problem in yours projects just add FILE_SHARE_WRITE.
Hope this will helpful.
Replyfor example, a new file was created in the folder i spying. I found this event, but unable to rename the file anyway now. Just have a try!
ReplyPlease describe what exactly you mean when writing this question?
ReplyThank you for your FileSpy. It is very useful for me to increase the efficiency of data processing. But I find ReadDirectoryChangesW() does not work if I use network drive to connect a directory existing on UNIX system and shared out by Samba. Do you have any idea how to make it work?
I can browse the content of the target folder,so the network is ok.But the function does not work.
ReplyError code 59 - An unexpected network error occurred. ERROR_UNEXP_NET_ERR.
ReplyIn my case,the error code is 59.
ReplyIn my case,the error code is 59.
ReplyThank you for the feedback. At the first the reason of the problem need to be determine. Just try to call GetLastError after each call of ReadDirectoryChanges to obtain error code.
ReplyOriginally posted by: David
Hi !
Is it possible to retrieve the PID of the process which carried out the modification ?
Thanks in advance,
David
Reply