当前位置: 首页>>代码示例>>C#>>正文


C# SHFILEOPSTRUCT类代码示例

本文整理汇总了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);
 }
开发者ID:byrod,项目名称:YAME,代码行数:8,代码来源:SHFILEOP.cs

示例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);
 }
开发者ID:andrey-kozyrev,项目名称:LinguaSpace,代码行数:9,代码来源:ShellUtils.cs

示例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);
 }
开发者ID:robotob,项目名称:Components,代码行数:9,代码来源:WindowsAPI.cs

示例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);
 }
开发者ID:hbre,项目名称:henning-me-tools,代码行数:14,代码来源:Program.cs

示例5: DeleteFileOperation

        private static void DeleteFileOperation(string filePath)
        {
            var fileop = new SHFILEOPSTRUCT
                             {
                                 wFunc = FoDelete,
                                 pFrom = filePath + '\0' + '\0',
                                 fFlags = FofAllowundo | FofNoconfirmation
                             };

            SHFileOperation(ref fileop);
        }
开发者ID:vmail,项目名称:main,代码行数:11,代码来源:FileOperations.cs

示例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);
        }
开发者ID:peeboo,项目名称:open-media-library,代码行数:11,代码来源:FileHelper.cs

示例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;
 }
开发者ID:nocmnt,项目名称:UVA-Arena,代码行数:11,代码来源:FileOperations.cs

示例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;
        }
开发者ID:jasonleenaylor,项目名称:libpalaso,代码行数:55,代码来源:PathUtilities.cs

示例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);
		}
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:14,代码来源:NativeMethods.cs

示例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;
     }
 }
开发者ID:gro-ove,项目名称:actools,代码行数:14,代码来源:FileUtils.cs

示例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);
     }
 }
开发者ID:jsschultz,项目名称:PTVS,代码行数:19,代码来源:ShellUtils.cs

示例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);
     }
 }
开发者ID:murrple-1,项目名称:ID3SQL,代码行数:15,代码来源:SHFileOperationWrapper.cs

示例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);
        }
开发者ID:HaKDMoDz,项目名称:eStd,代码行数:17,代码来源:NativeMethods.cs

示例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;
     }
 }
开发者ID:EmuDevs,项目名称:EDTerraria,代码行数:18,代码来源:FileOperationAPIWrapper.cs

示例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;
         }
 }
开发者ID:varunkho,项目名称:SendTodropbox,代码行数:18,代码来源:SHFileOperation.cs


注:本文中的SHFILEOPSTRUCT类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。