void log_webfiles_init () { TCHAR tszPath [MAX_PATH] = _T (""); GetTempPath (MAX_PATH, tszPath); _tcscat (tszPath, _T ("\\fdmflvsniff")); SHFILEOPSTRUCT sfos = {0}; sfos.wFunc = FO_DELETE; sfos.pFrom = tszPath; sfos.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR; SHFileOperation (&sfos); }
static bool DeleteDirectory(const std::string& dir) { // SHFileOperation requires file names to be terminated with two \0s std::string tmpDir = dir + std::string(1, '\0'); SHFILEOPSTRUCT fop; fop.wFunc = FO_DELETE; fop.pFrom = tmpDir.c_str(); fop.fFlags = FOF_NO_UI; return (SHFileOperation(&fop) == 0); }
static int op_removesl(void *data, const char *src, const char *dst) { #ifndef _WIN32 char *escaped; char cmd[16 + PATH_MAX]; int result; escaped = escape_filename(src, 0); if(escaped == NULL) return -1; snprintf(cmd, sizeof(cmd), "rm -rf %s", escaped); LOG_INFO_MSG("Running rm command: \"%s\"", cmd); result = background_and_wait_for_errors(cmd); free(escaped); return result; #else if(is_dir(src)) { char buf[PATH_MAX]; int err; int i; snprintf(buf, sizeof(buf), "%s%c", src, '\0'); for(i = 0; buf[i] != '\0'; i++) if(buf[i] == '/') buf[i] = '\\'; SHFILEOPSTRUCTA fo = { .hwnd = NULL, .wFunc = FO_DELETE, .pFrom = buf, .pTo = NULL, .fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI, }; err = SHFileOperation(&fo); log_msg("Error: %d", err); return err; } else { int ok; DWORD attributes = GetFileAttributesA(src); if(attributes & FILE_ATTRIBUTE_READONLY) SetFileAttributesA(src, attributes & ~FILE_ATTRIBUTE_READONLY); ok = DeleteFile(src); if(!ok) LOG_WERROR(GetLastError()); return !ok; } #endif }
void FileActionThread::DoFileAction(FileAction action, const wxArrayString& sources, const wxString& targetDir, bool allowUndo) { //static if (sources.empty()) return; #ifdef __WXMSW__ // Paths have to be double-null terminated wxString filePaths; for (unsigned int i = 0; i < sources.GetCount(); ++i) { filePaths += sources[i] + wxT('\0'); } const wxString target = targetDir + wxT('\0'); // The File Operation Structure SHFILEOPSTRUCT SHFileOp; ZeroMemory(&SHFileOp, sizeof(SHFILEOPSTRUCT)); SHFileOp.hwnd = NULL; SHFileOp.pFrom = filePaths.c_str(); SHFileOp.fFlags = FOF_NOCONFIRMMKDIR; if (allowUndo) SHFileOp.fFlags |= FOF_ALLOWUNDO; switch (action) { case FILEACTION_DELETE: SHFileOp.wFunc = FO_DELETE; break; case FILEACTION_DELETE_SILENT: SHFileOp.wFunc = FO_DELETE; SHFileOp.fFlags |= FOF_SILENT|FOF_NOCONFIRMATION|FOF_NOERRORUI; break; case FILEACTION_COPY: SHFileOp.wFunc = FO_COPY; SHFileOp.pTo = target.c_str(); break; case FILEACTION_MOVE: SHFileOp.wFunc = FO_MOVE; SHFileOp.pTo = target.c_str(); break; default: wxASSERT(false); return; } // Do the file operation SHFileOperation(&SHFileOp); #endif //__WXMSW__ return; }
int DeleteFolder(std::wstring path) { if (path.back() == '\\') path.pop_back(); path.push_back('\0'); SHFILEOPSTRUCT fos = {0}; fos.wFunc = FO_DELETE; fos.pFrom = path.c_str(); fos.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT; return SHFileOperation(&fos); }
void EmptyFolder() { SHFILEOPSTRUCT file_op = { NULL, FO_DELETE, tszRoot, _T(""), FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION, false, 0, _T("") }; SHFileOperation(&file_op); }
bool CTGitPathList::DeleteViaShell(LPCTSTR path, bool bTrash, bool bShowErrorUI) { SHFILEOPSTRUCT shop = {0}; shop.wFunc = FO_DELETE; shop.pFrom = path; shop.fFlags = FOF_NOCONFIRMATION|FOF_NO_CONNECTED_ELEMENTS; if (!bShowErrorUI) shop.fFlags |= FOF_NOERRORUI | FOF_SILENT; if (bTrash) shop.fFlags |= FOF_ALLOWUNDO; const bool bRet = (SHFileOperation(&shop) == 0); return bRet; }
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { HWND hWnd = GetConsoleWindow(); ShowWindow(hWnd, SW_HIDE); SHFILEOPSTRUCT sh; sh.wFunc = FO_DELETE; sh.pFrom = L"d:\\1\2\0"; sh.pTo = NULL; sh.fFlags = FOF_NOCONFIRMATION | FOF_SILENT; sh.hNameMappings = 0; sh.lpszProgressTitle = NULL; SHFileOperation (&sh); }
void CTreeFileCtrl::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) { TV_DISPINFO* pDispInfo = (TV_DISPINFO*)pNMHDR; if (pDispInfo->item.pszText) { SHFILEOPSTRUCT shfo; ZeroMemory(&shfo, sizeof(SHFILEOPSTRUCT)); shfo.hwnd = AfxGetMainWnd()->GetSafeHwnd(); shfo.wFunc = FO_RENAME; shfo.fFlags = FOF_ALLOWUNDO; CString sFrom = ItemToPath(pDispInfo->item.hItem); int nFromLength = sFrom.GetLength(); TCHAR* pszFrom = new TCHAR[nFromLength + 2]; _tcscpy(pszFrom, sFrom); pszFrom[nFromLength+1] = _T('\0'); shfo.pFrom = pszFrom; HTREEITEM hParent = GetParentItem(pDispInfo->item.hItem); CString sParent = ItemToPath(hParent); CString sTo; if (IsDrive(sParent)) sTo = sParent + pDispInfo->item.pszText; else sTo = sParent + _T("\\") + pDispInfo->item.pszText; int nToLength = _tcslen(sTo); TCHAR* pszTo = new TCHAR[nToLength + 2]; _tcscpy(pszTo, sTo); pszTo[nToLength+1] = _T('\0'); shfo.pTo = pszTo; //Let the shell perform the actual rename if (SHFileOperation(&shfo) == 0 && shfo.fAnyOperationsAborted == FALSE) { *pResult = TRUE; //Update its text SetItemText(pDispInfo->item.hItem, pDispInfo->item.pszText); //Also update the icons for it CString sPath = ItemToPath(pDispInfo->item.hItem); SetItemImage(pDispInfo->item.hItem, GetIconIndex(sPath), GetSelIconIndex(sPath)); } //Don't forget to free up the memory we allocated delete [] pszFrom; delete [] pszTo; } *pResult = 0; }
void DeletetoRecycle(char * FN) { #ifdef WIN32 SHFILEOPSTRUCT FileOp; FileOp.hwnd = NULL; FileOp.wFunc = FO_DELETE; FileOp.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR | FOF_ALLOWUNDO; FileOp.pFrom = FN; FileOp.pTo = NULL; SHFileOperation(&FileOp); #endif }
bool FileSystem::FolderCopy(const String& from, const String& to) const { if (!IsFolderExist(from) || !IsFolderExist(to)) return false; SHFILEOPSTRUCT s = { 0 }; s.hwnd = o2Application.mHWnd; s.wFunc = FO_COPY; s.fFlags = FOF_SILENT; s.pTo = to; s.pFrom = from; auto res = SHFileOperation(&s); return res == 0; }
// Rename pszOldName to pszNewName. // support File or Directory. Rename(_T("C:\\DirOld"), _T("C:\\DirNew")); bool CFileOps_i::Rename(LPCTSTR pszOldName, LPCTSTR pszNewName) { SHFILEOPSTRUCT FileOp = {0, }; FileOp.wFunc = FO_RENAME; FileOp.pFrom = (LPCTSTR)pszOldName; FileOp.pTo = (LPCTSTR)pszNewName; FileOp.fFlags = (FILEOP_FLAGS)(FOF_SILENT|FOF_NOCONFIRMATION); if(SHFileOperation(&FileOp) == 0) // if will not be placed in the Recycle Bin, use DeleteFile. return TRUE; else return FALSE; }
bool CTSVNPathList::DeleteViaShell(LPCTSTR path, bool bTrash, HWND hErrorWnd) { SHFILEOPSTRUCT shop = {0}; shop.hwnd = hErrorWnd; shop.wFunc = FO_DELETE; shop.pFrom = path; shop.fFlags = FOF_NOCONFIRMATION|FOF_SILENT|FOF_NO_CONNECTED_ELEMENTS; if (hErrorWnd == NULL) shop.fFlags |= FOF_NOERRORUI; if (bTrash) shop.fFlags |= FOF_ALLOWUNDO; const bool bRet = (SHFileOperation(&shop) == 0); return bRet; }
bool et::removeDirectory(const std::string& name) { ET_STRING_TYPE aName = ET_STRING_TO_PARAM_TYPE(name); aName.resize(aName.size() + 1); aName.back() = 0; SHFILEOPSTRUCT fop = { }; fop.wFunc = FO_DELETE; fop.pFrom = aName.c_str(); fop.fFlags = FOF_NO_UI; return SHFileOperation(&fop) == 0; }
static bool CopyDirectory(const std::string& source, const std::string& destination) { // SHFileOperation requires file names to be terminated with two \0s std::string tmpSource = source + std::string(1, '\0'); std::string tmpDestination = destination + std::string(1, '\0'); SHFILEOPSTRUCT fop; fop.wFunc = FO_COPY; fop.pFrom = tmpSource.c_str(); fop.pTo = tmpDestination.c_str(); fop.fFlags = FOF_NO_UI; return (SHFileOperation(&fop) == 0); }
bool RenameFile(wxWindow* parent, wxString dir, wxString from, wxString to) { if (dir.Right(1) != _T("\\") && dir.Right(1) != _T("/")) dir += wxFileName::GetPathSeparator(); #ifdef __WXMSW__ to = to.Left(255); if ((to.Find('/') != -1) || (to.Find('\\') != -1) || (to.Find(':') != -1) || (to.Find('*') != -1) || (to.Find('?') != -1) || (to.Find('"') != -1) || (to.Find('<') != -1) || (to.Find('>') != -1) || (to.Find('|') != -1)) { wxMessageBox(_("Filenames may not contain any of the following characters: / \\ : * ? \" < > |"), _("Invalid filename"), wxICON_EXCLAMATION); return false; } SHFILEOPSTRUCT op; memset(&op, 0, sizeof(op)); from = dir + from + _T(" "); from.SetChar(from.Length() - 1, '\0'); op.pFrom = from; to = dir + to + _T(" "); to.SetChar(to.Length()-1, '\0'); op.pTo = to; op.hwnd = (HWND)parent->GetHandle(); op.wFunc = FO_RENAME; op.fFlags = FOF_ALLOWUNDO; return SHFileOperation(&op) == 0; #else if ((to.Find('/') != -1) || (to.Find('*') != -1) || (to.Find('?') != -1) || (to.Find('<') != -1) || (to.Find('>') != -1) || (to.Find('|') != -1)) { wxMessageBox(_("Filenames may not contain any of the following characters: / * ? < > |"), _("Invalid filename"), wxICON_EXCLAMATION); return false; } return wxRename(dir + from, dir + to) == 0; #endif }
// // DeleteFolder // // Delete folder // HRESULT CLevelZapContextMenuExt::DeleteFolder(const HWND p_hParentWnd, CString p_Path) const { SHFILEOPSTRUCT fileOpStruct = {0}; fileOpStruct.hwnd = p_hParentWnd; fileOpStruct.wFunc = FO_DELETE; fileOpStruct.pTo = 0; fileOpStruct.fFlags = FOF_ALLOWUNDO | FOF_WANTNUKEWARNING | FOF_SILENT; if (Util::PathIsDirectoryEmptyEx(p_Path)) fileOpStruct.fFlags |= FOF_NOCONFIRMATION; p_Path.AppendChar(L'\0'); fileOpStruct.pFrom = p_Path; if (p_hParentWnd == 0) fileOpStruct.fFlags |= FOF_NOERRORUI; int hRes = SHFileOperation(&fileOpStruct); Util::OutputDebugStringEx(L"Delete 0x%08x | %s", hRes, p_Path); return hRes; }
bool et::removeDirectory(const std::string& name) { std::string doubleNullTerminated(name.size() + 1, 0); std::copy(name.begin(), name.end(), doubleNullTerminated.begin()); SHFILEOPSTRUCT fop = { }; fop.hwnd = 0; fop.wFunc = FO_DELETE; fop.pFrom = doubleNullTerminated.c_str(); fop.fFlags = FOF_NO_UI; return SHFileOperation(&fop) == 0; }
bool WaveEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo &metaInfo, const unsigned int duration, const QString &outputFile, volatile bool *abortFlag) { SHFILEOPSTRUCTW fileOperation; memset(&fileOperation, 0, sizeof(SHFILEOPSTRUCTW)); fileOperation.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_FILESONLY; emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile)); fileOperation.wFunc = FO_COPY; /* if(lamexp_temp_folder().compare(QFileInfo(sourceFile).canonicalPath(), Qt::CaseInsensitive) == 0) { //If the source is in the TEMP folder take shortcut and move the file emit messageLogged(QString("Moving file \"%1\" to \"%2\"").arg(sourceFile, outputFile)); fileOperation.wFunc = FO_MOVE; } else { //...otherwise we actually copy the file in order to keep the source emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile)); fileOperation.wFunc = FO_COPY; } */ size_t srcLen = wcslen(reinterpret_cast<const wchar_t*>(sourceFile.utf16())) + 3; wchar_t *srcBuffer = new wchar_t[srcLen]; memset(srcBuffer, 0, srcLen * sizeof(wchar_t)); wcsncpy_s(srcBuffer, srcLen, reinterpret_cast<const wchar_t*>(sourceFile.utf16()), _TRUNCATE); FIX_SEPARATORS (srcBuffer); fileOperation.pFrom = srcBuffer; size_t outLen = wcslen(reinterpret_cast<const wchar_t*>(outputFile.utf16())) + 3; wchar_t *outBuffer = new wchar_t[outLen]; memset(outBuffer, 0, outLen * sizeof(wchar_t)); wcsncpy_s(outBuffer, outLen, reinterpret_cast<const wchar_t*>(outputFile.utf16()), _TRUNCATE); FIX_SEPARATORS (outBuffer); fileOperation.pTo = outBuffer; emit statusUpdated(0); int result = SHFileOperation(&fileOperation); emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", result)); delete [] srcBuffer; delete [] outBuffer; return (result == 0 && fileOperation.fAnyOperationsAborted == false); }
bool FileSystemManager::copyFiles(vector<FileSystemActor *> &objList, QString destDir, vector<FileSystemActor *> &failedObj, bool confirm) { SHFILEOPSTRUCT fileOperation = { 0 }; QString toPath(destDir), tmpStr; bool rc = false; vector<BumpObject *> objFailed; TCHAR * fromPaths = allocateStringFromPathsArray(objList); TCHAR * fromPathsOffset = fromPaths; // ensure that there are no virtual folders in the set and build the // files to copy from for (uint i = 0; i < objList.size(); i++) { FileSystemActor * fsData = objList[i]; // Virtual folders should warn the user if (fsData->isFileSystemType(Virtual)) { MessageClearPolicy clearPolicy; clearPolicy.setTimeout(2); scnManager->messages()->addMessage(new Message("copyFiles", QT_TR_NOOP("Virtual Folders, such as My Computer and the Recycle Bin, cannot be copied!"), Message::Warning, clearPolicy)); delete fromPaths; return false; } // build the string lstrcpy(fromPathsOffset, (LPCTSTR) fsData->getFullPath().utf16()); fromPathsOffset += fsData->getFullPath().size() + 1; } // build the string of the path to copy to TCHAR newp[MAX_PATH] = {0}; lstrcpy(newp, (LPCTSTR) toPath.utf16()); fileOperation.hwnd = winOS->GetWindowsHandle(); fileOperation.wFunc = FO_COPY; fileOperation.pFrom = fromPaths; fileOperation.pTo = newp; fileOperation.fFlags = FOF_ALLOWUNDO | (confirm ? NULL : FOF_NOCONFIRMATION); // do the windows file operations for Copy int result = SHFileOperation(&fileOperation); if (result != 0) failedObj = objList; delete fromPaths; return result == 0; }
void silently_remove_directory(LPCTSTR dir) { SHFILEOPSTRUCT file_op = { NULL, FO_DELETE, dir, "", FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT, false, 0, "" }; SHFileOperation(&file_op); }
bool CSystem::ShellCopy(const char* from, const char* dest) { SHFILEOPSTRUCT fileOp = { 0 }; fileOp.wFunc = FO_COPY; TCHAR newFrom[MAX_PATH]; _tcscpy_s(newFrom, from); newFrom[_tcsclen(from) + 1] = 0; fileOp.pFrom = newFrom; TCHAR newTo[MAX_PATH]; _tcscpy_s(newTo, dest); newTo[_tcsclen(dest) + 1] = 0; fileOp.pTo = newTo; fileOp.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR; return SHFileOperation(&fileOp) == 0; }
BOOL UtilMoveFileToRecycleBin(LPCTSTR lpFileName) { ASSERT(lpFileName); if(!lpFileName)return false; const UINT len=_tcslen(lpFileName); std::vector<TCHAR> Buffer(len+2); _tcsncpy_s(&Buffer[0],len+1,lpFileName,len+1); Buffer.back()=_T('\0'); SHFILEOPSTRUCT shfo={0}; shfo.wFunc=FO_DELETE; //削除 shfo.pFrom=&Buffer[0];//ファイル名のリスト末尾は\0\0で終わる必要有り shfo.fFlags=FOF_SILENT/*進捗状況を表示しない*/|FOF_ALLOWUNDO/*UNDO情報付加;ごみ箱へ*/|FOF_NOCONFIRMATION/*確認ダイアログを表示しない*/; return SHFileOperation(&shfo); }
BOOLEAN SdkCopyFile( IN PWSTR Destine, IN PWSTR Source ) { SHFILEOPSTRUCT FileOp = {0}; FileOp.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR; FileOp.pFrom = Source; FileOp.pTo = Destine; FileOp.wFunc = FO_COPY; return !SHFileOperation(&FileOp); }
bool CFileOps_i::Move(HWND hWnd, LPCTSTR pszFrom, LPCTSTR pTo, bool bSilent) { SHFILEOPSTRUCT FileOp = {0, }; FileOp.hwnd = hWnd; FileOp.wFunc = FO_MOVE; FileOp.pFrom = (LPCTSTR)pszFrom; FileOp.pTo = (LPCTSTR)pTo; FileOp.fFlags = (FILEOP_FLAGS)(bSilent ? (FOF_SILENT|FOF_NOCONFIRMATION): (FOF_NOCONFIRMATION|FOF_NOERRORUI)); if(SHFileOperation(&FileOp) == 0) return TRUE; else return FALSE; }
bool FileSystemManager::deleteFileByName(QString filePath, bool silent, bool skipRecycleBin, bool confirm) { TCHAR filep[MAX_PATH] = {0}; lstrcpy(filep, (LPCTSTR) filePath.utf16()); SHFILEOPSTRUCT fileOp = { 0 }; fileOp.hwnd = winOS->GetWindowsHandle(); fileOp.wFunc = FO_DELETE; fileOp.pFrom = filep; fileOp.pTo = L"\0\0"; fileOp.fFlags = (skipRecycleBin ? 0 : FOF_ALLOWUNDO) | (confirm ? NULL : FOF_NOCONFIRMATION) | (silent ? FOF_SILENT : 0); bool result = (SHFileOperation(&fileOp) == 0) && !fileOp.fAnyOperationsAborted; return result; }
int NTrash(const QString &path, QString *error) { QString new_path = path; new_path.append("00"); new_path[new_path.size() - 2] = 0; new_path[new_path.size() - 1] = 0; SHFILEOPSTRUCT shfo = {0}; shfo.wFunc = FO_DELETE; shfo.pFrom = (wchar_t *)(new_path.utf16()); shfo.fFlags = FOF_NOCONFIRMATION | FOF_SIMPLEPROGRESS | FOF_NOERRORUI | FOF_ALLOWUNDO; shfo.fAnyOperationsAborted = FALSE; shfo.hNameMappings = NULL; shfo.pTo = NULL; shfo.lpszProgressTitle = NULL; return SHFileOperation(&shfo); }
/** * @brief Move a file to trash bin * @param string _filename * @return bool */ bool UM::moveFileToTrash(const QString &_filename) { wchar_t path[MAX_PATH]; memset(path, 0, sizeof(path)); int l = _filename.toWCharArray(path); path[l] = '\0'; SHFILEOPSTRUCT shfos; shfos.wFunc = FO_DELETE; shfos.pFrom = path; shfos.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT; int ret = SHFileOperation(&shfos); return ret == 0; }
// // MoveFile // // Move file(s) // HRESULT CLevelZapContextMenuExt::MoveFile(const HWND p_hParentWnd, CString p_Path, CString p_FolderTo) const { if (p_Path.IsEmpty()) return S_OK; SHFILEOPSTRUCT fileOpStruct = {0}; fileOpStruct.hwnd = p_hParentWnd; fileOpStruct.wFunc = FO_MOVE; p_Path.AppendChar(L'\0'); fileOpStruct.pFrom = p_Path; p_FolderTo.AppendChar(L'\0'); fileOpStruct.pTo = p_FolderTo; fileOpStruct.fFlags = FOF_MULTIDESTFILES | FOF_ALLOWUNDO | FOF_SILENT; if (p_hParentWnd == 0) fileOpStruct.fFlags |= (FOF_NOCONFIRMATION | FOF_NOERRORUI); int hRes = SHFileOperation(&fileOpStruct); if (fileOpStruct.fAnyOperationsAborted) hRes = E_ABORT; Util::OutputDebugStringEx(L"Move 0x%08x | %s -> %s\n", hRes, p_Path, p_FolderTo); return hRes; }
/* ======================================================================= */ INT DelTree(HWND H, PCHAR Path) { SHFILEOPSTRUCT FO; memset(&FO, 0, sizeof(FO)); FO.hwnd = H; FO.wFunc = FO_DELETE; CHAR BasePathDoubleTerminated[MAX_PATH + 1]; memset(BasePathDoubleTerminated, 0, sizeof(BasePathDoubleTerminated)); strcpy(BasePathDoubleTerminated, Path); FO.pFrom = BasePathDoubleTerminated; FO.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION; FO.fAnyOperationsAborted = TRUE; FO.hNameMappings = NULL; FO.lpszProgressTitle = WindowName; return SHFileOperation(&FO); }