本文整理汇总了C#中SHFILEOPSTRUCT类的典型用法代码示例。如果您正苦于以下问题:C# SHFILEOPSTRUCT类的具体用法?C# SHFILEOPSTRUCT怎么用?C# SHFILEOPSTRUCT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SHFILEOPSTRUCT类属于命名空间,在下文中一共展示了SHFILEOPSTRUCT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendToTrash
public static void SendToTrash(string path)
{
SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT();
fileop.wFunc = FO_DELETE;
fileop.pFrom = path + '\0' + '\0';
fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
SHFileOperation(ref fileop);
}
示例2: CopyFiles
public static bool CopyFiles(String from, String to)
{
SHFILEOPSTRUCT op = new SHFILEOPSTRUCT();
op.wFunc = FO_Func.FO_COPY;
op.fFlags = (ushort)FO_Func.FOF_ALLOWUNDO;
op.pFrom = from;
op.pTo = to;
return (SHFileOperation(ref op) == 0 && !op.fAnyOperationsAborted);
}
示例3: deleteFileOrFolder2Bin
public static int deleteFileOrFolder2Bin(string ff)
{
if (ff.EndsWith("\\")) ff = ff.Remove(ff.Length - 1, 1);
SHFILEOPSTRUCT shf = new SHFILEOPSTRUCT();
shf.wFunc = FO_DELETE;
shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
shf.pFrom = ff + '\0' + '\0';
return SHFileOperation(ref shf);
}
示例4: DateiInPapierkorb
/// <summary>
/// Verschiebt eine Datei in den Papierkorb
/// </summary>
/// <param name="filePath"></param>
private static void DateiInPapierkorb(string filePath)
{
var fileop = new SHFILEOPSTRUCT
{
wFunc = FO_DELETE,
pFrom = (filePath + '\0' + '\0'),
fFlags = (FOF_ALLOWUNDO | FOF_NOCONFIRMATION)
};
SHFileOperation(ref fileop);
}
示例5: DeleteFileOperation
private static void DeleteFileOperation(string filePath)
{
var fileop = new SHFILEOPSTRUCT
{
wFunc = FoDelete,
pFrom = filePath + '\0' + '\0',
fFlags = FofAllowundo | FofNoconfirmation
};
SHFileOperation(ref fileop);
}
示例6: DeleteFileToRecycleBin
public static void DeleteFileToRecycleBin(string filename)
{
SHFILEOPSTRUCT shf = new SHFILEOPSTRUCT();
shf.wFunc = FO_DELETE;
shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
shf.pFrom = filename + "\0";
int result = SHFileOperation(ref shf);
if (result != 0)
Utilities.DebugLine("error: {0} while moving file {1} to recycle bin", result, filename);
}
示例7: CallSH
public static bool CallSH(FileOperationType type, string[] from, string to, FileOperationFlags flags)
{
var fs = new SHFILEOPSTRUCT();
fs.wFunc = type;
if (from.Length > 0)
fs.pFrom = string.Join("\0", from) + "\0\0";
if (to.Length > 0)
fs.pTo = to + "\0\0";
fs.fFlags = flags;
return SHFileOperation(ref fs) == 0;
}
示例8: DeleteToRecycleBin
/// <summary>
/// Delete a file or directory by moving it to the trash bin
/// </summary>
/// <param name="filePath">Full path of the file.</param>
/// <returns><c>true</c> if successfully deleted.</returns>
public static bool DeleteToRecycleBin(string filePath)
{
if (PlatformUtilities.Platform.IsWindows)
{
if (!File.Exists(filePath) && !Directory.Exists(filePath))
return false;
// alternative using visual basic dll:
// FileSystem.DeleteDirectory(item.FolderPath,UIOption.OnlyErrorDialogs), RecycleOption.SendToRecycleBin);
//moves it to the recyle bin
var shf = new SHFILEOPSTRUCT();
shf.wFunc = FO_DELETE;
shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
string pathWith2Nulls = filePath + "\0\0";
shf.pFrom = pathWith2Nulls;
SHFileOperation(ref shf);
return !shf.fAnyOperationsAborted;
}
// On Linux we'll have to move the file to $XDG_DATA_HOME/Trash/files and create
// a filename.trashinfo file in $XDG_DATA_HOME/Trash/info that contains the original
// filepath and the deletion date. See http://stackoverflow.com/a/20255190
// and http://freedesktop.org/wiki/Specifications/trash-spec/.
// Environment.SpecialFolder.LocalApplicationData corresponds to $XDG_DATA_HOME.
// move file or directory
if (Directory.Exists(filePath) || File.Exists(filePath))
{
var trashPath = Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData), "Trash");
var trashedFileName = Path.GetRandomFileName();
if (!Directory.Exists(trashPath))
{
// in case the trash bin doesn't exist we create it. This can happen e.g.
// on the build machine
Directory.CreateDirectory(Path.Combine(trashPath, "files"));
Directory.CreateDirectory(Path.Combine(trashPath, "info"));
}
var recyclePath = Path.Combine(Path.Combine(trashPath, "files"), trashedFileName);
WriteTrashInfoFile(trashPath, filePath, trashedFileName);
// Directory.Move works for directories and files
DirectoryUtilities.MoveDirectorySafely(filePath, recyclePath);
return true;
}
return false;
}
示例9: DeleteToRecycleBin
public static void DeleteToRecycleBin(string fileName)
{
if (!File.Exists(fileName) && !Directory.Exists(fileName))
throw new FileNotFoundException("File not found.", fileName);
SHFILEOPSTRUCT info = new SHFILEOPSTRUCT();
info.hwnd = Gui.WorkbenchSingleton.MainWin32Window.Handle;
info.wFunc = FO_FUNC.FO_DELETE;
info.fFlags = FILEOP_FLAGS.FOF_ALLOWUNDO | FILEOP_FLAGS.FOF_NOCONFIRMATION;
info.lpszProgressTitle = "Delete " + Path.GetFileName(fileName);
info.pFrom = fileName + "\0"; // pFrom is double-null-terminated
int result = SHFileOperation(ref info);
if (result != 0)
throw new IOException("Could not delete file " + fileName + ". Error " + result, result);
}
示例10: DeleteFile
private static bool DeleteFile(string[] path, FileOperationFlags flags) {
if (path == null || path.All(x => x == null)) return false;
try {
var fs = new SHFILEOPSTRUCT {
wFunc = FileOperationType.FO_DELETE,
pFrom = string.Join("\0", path.Where(x => x != null)) + "\0\0",
fFlags = flags
};
SHFileOperation(ref fs);
return true;
} catch (Exception) {
return false;
}
}
示例11: RecursivelyDeleteDirectory
/// <summary>
/// Recursively deletes a directory using the shell API which can
/// handle long file names
/// </summary>
/// <param name="dir"></param>
public static void RecursivelyDeleteDirectory(string dir, bool silent = false) {
SHFILEOPSTRUCT fileOp = new SHFILEOPSTRUCT();
fileOp.pFrom = dir + '\0'; // pFrom must be double null terminated
fileOp.wFunc = FO_Func.FO_DELETE;
fileOp.fFlags = FILEOP_FLAGS_ENUM.FOF_NOCONFIRMATION |
FILEOP_FLAGS_ENUM.FOF_NOERRORUI;
if (silent) {
fileOp.fFlags |= FILEOP_FLAGS_ENUM.FOF_SILENT;
}
int res = SHFileOperation(ref fileOp);
if (res != 0) {
throw new IOException("Failed to delete dir " + res);
}
}
示例12: DeleteFileOrFolder
public static void DeleteFileOrFolder(string path)
{
try
{
SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT();
fileop.wFunc = FO_DELETE;
fileop.pFrom = path + '\0' + '\0';
fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
SHFileOperation(ref fileop);
}
catch(Exception ex)
{
throw new ID3SQLException("Recycle option not available on this system", ex);
}
}
示例13: DeleteToRecycleBin
public static void DeleteToRecycleBin(string fileName, bool showConfirmation)
{
SHFILEOPSTRUCT shf = new SHFILEOPSTRUCT();
shf.hwnd = IntPtr.Zero;
shf.wFunc = FO_Func.FO_DELETE;
if (showConfirmation)
{
shf.fFlags = FOF_ALLOWUNDO;
}
else
{
shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
}
shf.pFrom = fileName + '\0';
SHFileOperation(ref shf);
}
示例14: DeleteFile
private static bool DeleteFile(string path, FileOperationFlags flags)
{
try
{
SHFILEOPSTRUCT fileOp = new SHFILEOPSTRUCT
{
wFunc = FileOperationType.FO_DELETE,
pFrom = path + '\0' + '\0',
fFlags = flags
};
SHFileOperation(ref fileOp);
return true;
}
catch (Exception)
{
return false;
}
}
示例15: CopyItems
public static bool CopyItems(List<string> items, string destination)
{
try
{
var fs = new SHFILEOPSTRUCT
{
wFunc = FileOperationType.FO_COPY,
pFrom = string.Join("\0", items.ToArray()) + '\0' + '\0',
pTo = destination + '\0' + '\0'
};
SHFileOperation(ref fs);
return true;
}
catch (Exception)
{
return false;
}
}