winapi - Ignoring exclusively locked files in SHFileOperation -


i using windows 7 professional , using shfileoperation() recursive copy 1 folder contents another. there locked file (opened exclusively application); need skip it, shfileoperation() returns 0x20 when tries copy file.

how can skip file during file copy operation?

update: code:

// // copydirectory() //  рекурсивное копирование содержимого одной директории в другую средствами windows // lpszsource      - исходная папка // lpszdestination - папка назначения // bool copydirectory( lpstr lpszsource, lpstr lpszdestination ) {     lpstr lpsznewsource = null;      // структура операции с файлами     shfileopstruct fileop = { 0 };      // выделим память под новый путь     lpsznewsource = (lpstr)calloc(strlen(lpszsource) + 50, 1);      // запишем новый путь с маской     wsprintf(lpsznewsource, "%s\\*", lpszsource);      // запишем параметры операции копирования     fileop.wfunc    = fo_copy;     fileop.pto  = lpszdestination;     fileop.pfrom    = lpszsource;     fileop.fflags   = fof_silent | fof_noconfirmmkdir | fof_noconfirmation | fof_noerrorui | fof_no_ui;      // выполняем операцию     int retval = shfileoperation( &fileop );      // освободим память     free_null(lpsznewsource);      debugprint(debug_info, "retval = %d\n", retval);      // возвращаем результат копирования     return retval == 0; } 

the shfileoperation() documentation says:

return value

type: int

returns 0 if successful; otherwise nonzero. applications should check 0 or nonzero.

it practice examine value of fanyoperationsaborted member of shfileopstruct. shfileoperation can return 0 success if user cancels operation. if not check fanyoperationsaborted return value, cannot know function accomplished full task asked of , might proceed under incorrect assumptions.

do not use getlasterror return values of function.

to examine nonzero values troubleshooting purposes, largely map defined in winerror.h. however, several of possible return values based on pre-win32 error codes, in cases overlap later winerror.h values without matching meaning. particular values detailed here, , these specific values these meanings should accepted on winerror.h codes.

in case, 0x20 not 1 of pre-win32 error codes, maps standard win32 error code, error_sharing_violation, appropriate situation 1 of files not accessed.

to skip offending file, enable fof_noerrorui flag in shfileopstruct::fflags field. shfileopstruct documentation says following flag:

fof_noerrorui

do not display dialog user if error occurs.

however, documentation this:

fanyoperationsaborted
type: bool

when function returns, member contains true if file operations aborted before completed; otherwise, false. operation can manually aborted user through ui or it can silently aborted system if fof_noerrorui or fof_noconfirmation flags set.

the documentation ifileoperation (which replaces shfileoperation() on vista , later) has more fof_noerrorui flag:

fof_noerrorui (0x0400)

do not display message user if error occurs. if flag set without fofx_earlyfailure, error treated if user had chosen ignore or continue in dialog box. halts current action, sets flag indicate action aborted, , proceeds rest of operation.

...

fofx_earlyfailure (0x00100000)

if fofx_earlyfailure set fof_noerrorui, entire set of operations stopped upon encountering error in operation. flag valid when fof_noerrorui set.

so, fof_noerrorui enabled, return value of error_sharing_violation, , shfileopstruct::fanyoperationsaborted field being set true, tell a file not accessed during copy, not which file specifically. not mean entire shfileoperation() task failed completely.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -