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


C# FileAttributes类代码示例

本文整理汇总了C#中FileAttributes的典型用法代码示例。如果您正苦于以下问题:C# FileAttributes类的具体用法?C# FileAttributes怎么用?C# FileAttributes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileAttributes类属于命名空间,在下文中一共展示了FileAttributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteLicense

        internal void WriteLicense(string path, string netsealId, LicenseFile licenseFile, FileAttributes attributes = 0)
        {
            if (string.IsNullOrWhiteSpace(path))
                throw new Exception("path");

            InternalWriteLicense(path, netsealId, licenseFile, attributes);
        }
开发者ID:abazad,项目名称:NetSeal-Helper,代码行数:7,代码来源:LicenseWriter.cs

示例2: btnSave_Click

        private void btnSave_Click(object sender, EventArgs e)
        {
            FileInfo fi = new FileInfo(this.openFileDialog1.FileName);
            FileAttributes fa = new FileAttributes();

            foreach(object o in this.chkListFileAttributes.CheckedItems)
            {
                fa = fa | (FileAttributes)(Enum)o;
            }

            try
            {
                if(fi.IsReadOnly) fi.IsReadOnly = false;
                fi.CreationTime = DateTime.Parse(this.txtCreationTime.Text);
                fi.LastAccessTime = DateTime.Parse(this.txtLastAccessTime.Text);
                fi.LastWriteTime = DateTime.Parse(this.txtLastWriteTime.Text);

                fi.Attributes = fa;
                getFileInfo(fi);

            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
开发者ID:joshuaphendrix,项目名称:FilePeeker,代码行数:25,代码来源:frmFilePeeker.cs

示例3: Node

 public Node(string name, FileAttributes attrs)
 {
     Attributes = attrs;
     Name = name;
     Parents = new HashSet<Node>();
     Contains = new HashSet<Node>();
 }
开发者ID:CosminLazar,项目名称:SystemWrapper,代码行数:7,代码来源:Node.cs

示例4: FromFileAttribs

        private static string FromFileAttribs(FileAttributes attribs)
        {
            var str = new StringBuilder(9);

            if ((attribs & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                str.Append('R');
            if ((attribs & FileAttributes.Archive) == FileAttributes.Archive)
                str.Append('A');
            if ((attribs & FileAttributes.System) == FileAttributes.System)
                str.Append('S');
            if ((attribs & FileAttributes.Hidden) == FileAttributes.Hidden)
                str.Append('H');
            if ((attribs & FileAttributes.Normal) == FileAttributes.Normal)
                str.Append('N');
            if ((attribs & FileAttributes.Directory) == FileAttributes.Directory)
                str.Append('D');
            if ((attribs & FileAttributes.Offline) == FileAttributes.Offline)
                str.Append('O');
            if ((attribs & FileAttributes.Compressed) == FileAttributes.Compressed)
                str.Append('C');
            if ((attribs & FileAttributes.Temporary) == FileAttributes.Temporary)
                str.Append('T');

            return str.ToString();
        }
开发者ID:Tyelpion,项目名称:IronAHK,代码行数:25,代码来源:Conversions.cs

示例5: GetAttributeLetter

 private static string GetAttributeLetter(FileAttributes fileAttributes, FileAttributes attributeToSearch, string attributeLetter)
 {
     if ((fileAttributes & attributeToSearch) == attributeToSearch)
         return attributeLetter;
     else
         return "-";
 }
开发者ID:almx,项目名称:ExRep,代码行数:7,代码来源:AttributeStringCreator.cs

示例6: Pack

        public static long Pack(FileAttributes fa)
        {
            long ret = 0;
            if ((fa & FileAttributes.Directory) > 0) ret |= Directory;

            return ret;
        }
开发者ID:drme,项目名称:disks-db,代码行数:7,代码来源:FileInfo.cs

示例7: FileTreeNodeProperty

 public FileTreeNodeProperty(string _name, FileTreeNodeType _type, string _fullPath, FileAttributes _fileSystemAttributes)
 {
     name__ = _name;
     type__ = _type;
     fullPath__ = _fullPath;
     fileSystemAttributes__ = _fileSystemAttributes;
 }
开发者ID:daxnet,项目名称:guluwin,代码行数:7,代码来源:FileTreeNodeProperty.cs

示例8: CreateFile

        public static Stream CreateFile(
            string fileName, FileAccess fileAccess, FileShare fileShare, FileMode fileMode, FileAttributes flags)
        {
            // TODO: This is not quite right, but it's close.
            //
            var nativeAccess = fileAccess;
            if ((nativeAccess & FileAccess.Read) != 0)
            {
                nativeAccess &= ~FileAccess.Read;
                nativeAccess |= (FileAccess)GENERIC_READ;
            }
            if ((nativeAccess & FileAccess.Write) != 0)
            {
                nativeAccess &= ~FileAccess.Write;
                nativeAccess |= (FileAccess)GENERIC_WRITE;
            }

            var handle = _CreateFile(fileName, nativeAccess, fileShare, IntPtr.Zero, fileMode, flags, IntPtr.Zero);
            if (handle.IsInvalid)
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }

            return new SimpleFileStream(handle);
        }
开发者ID:DeCarabas,项目名称:sudo,代码行数:25,代码来源:NativeMethods.cs

示例9: PathAlreadyExistsAsDirectory

 public void PathAlreadyExistsAsDirectory(FileAttributes attributes)
 {
     string path = GetTestFileName();
     DirectoryInfo testDir = Directory.CreateDirectory(Path.Combine(TestDirectory, path));
     testDir.Attributes = attributes;
     Assert.Equal(testDir.FullName, new DirectoryInfo(TestDirectory).CreateSubdirectory(path).FullName);
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:7,代码来源:CreateSubdirectory.cs

示例10: UnixInvalidAttributes

 public void UnixInvalidAttributes(FileAttributes attr)
 {
     var path = GetTestFilePath();
     File.Create(path).Dispose();
     Set(path, attr);
     Assert.Equal(FileAttributes.Normal, Get(path));
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:7,代码来源:GetSetAttributes.cs

示例11: EnumerateChildrenInternal

        internal static IEnumerable<IFileSystemInformation> EnumerateChildrenInternal(
            string directory,
            ChildType childType,
            string searchPattern,
            System.IO.SearchOption searchOption,
            FileAttributes excludeAttributes,
            IFileService fileService)
        {
            // We want to be able to see all files as we recurse and open new find handles (that might be over MAX_PATH).
            // We've already normalized our base directory.
            string extendedDirectory = Paths.AddExtendedPrefix(directory);

            // The assertion here is that we want to find files that match the desired pattern in all subdirectories, even if the
            // subdirectories themselves don't match the pattern. That requires two passes to avoid overallocating for directories
            // with a large number of files.

            // First look for items that match the given search pattern in the current directory
            using (FindOperation findOperation = new FindOperation(Paths.Combine(extendedDirectory, searchPattern)))
            {
                FindResult findResult;
                while ((findResult = findOperation.GetNextResult()) != null)
                {
                    bool isDirectory = (findResult.Attributes & FileAttributes.FILE_ATTRIBUTE_DIRECTORY) == FileAttributes.FILE_ATTRIBUTE_DIRECTORY;

                    if ((findResult.Attributes & excludeAttributes) == 0
                        && findResult.FileName != "."
                        && findResult.FileName != ".."
                        && ((isDirectory && childType == ChildType.Directory)
                            || (!isDirectory && childType == ChildType.File)))
                    {
                        yield return FileSystemInformation.Create(findResult, directory, fileService);
                    }
                }
            }

            if (searchOption != System.IO.SearchOption.AllDirectories) yield break;

            // Now recurse into each subdirectory
            using (FindOperation findOperation = new FindOperation(Paths.Combine(extendedDirectory, "*"), directoriesOnly: true))
            {
                FindResult findResult;
                while ((findResult = findOperation.GetNextResult()) != null)
                {
                    // Unfortunately there is no guarantee that the API will return only directories even if we ask for it
                    bool isDirectory = (findResult.Attributes & FileAttributes.FILE_ATTRIBUTE_DIRECTORY) == FileAttributes.FILE_ATTRIBUTE_DIRECTORY;

                    if ((findResult.Attributes & excludeAttributes) == 0
                        && isDirectory
                        && findResult.FileName != "."
                        && findResult.FileName != "..")
                    {
                        foreach (var child in EnumerateChildrenInternal(Paths.Combine(directory, findResult.FileName), childType, searchPattern,
                            searchOption, excludeAttributes, fileService))
                        {
                            yield return child;
                        }
                    }
                }
            }
        }
开发者ID:JeremyKuhne,项目名称:XTask,代码行数:60,代码来源:DirectoryInformation.cs

示例12: WriteAllBytes

 public void WriteAllBytes(string path, byte[] bytes, FileAttributes attributes)
 {
     if (File.Exists(path))
         File.SetAttributes(path, FileAttributes.Normal);
     File.WriteAllBytes(path, bytes);
     File.SetAttributes(path, attributes);
 }
开发者ID:Xarlot,项目名称:DXVcs2Git,代码行数:7,代码来源:FileSystem.cs

示例13: AddTree

        public static void AddTree(DirNode dirNode, string dirPrefix, string filePrefix, int width, int depth, int fileSizeInKB, FileAttributes? fa = null, DateTime? lmt = null)
        {
            for (int i = 0; i < width; ++i)
            {
                string fileName = i == 0 ? filePrefix : filePrefix + "_" + i;
                FileNode fileNode = new FileNode(fileName)
                {
                    SizeInByte = 1024L * fileSizeInKB,
                    FileAttr = fa,
                    LastModifiedTime = lmt,
                };

                dirNode.AddFileNode(fileNode);
            }

            if (depth > 0)
            {
                for (int i = 0; i < width; ++i)
                {
                    string dirName = i == 0 ? dirPrefix : dirPrefix + "_" + i;
                    DirNode subDirNode = dirNode.GetDirNode(dirName);
                    if (subDirNode == null)
                    {
                        subDirNode = new DirNode(dirName);
                        dirNode.AddDirNode(subDirNode);
                    }

                    DMLibDataHelper.AddTree(subDirNode, dirPrefix, filePrefix, width, depth - 1, fileSizeInKB, fa, lmt: lmt);
                }
            }
        }
开发者ID:ggais,项目名称:azure-storage-net-data-movement,代码行数:31,代码来源:DMLibDataHelper.cs

示例14: LoadFileConfiguration

 public LoadFileConfiguration(string sourceFile, string targetFile,
     FileAttributes targetFileAttributes = FileAttributes.Normal)
 {
     SourceFile = sourceFile;
     TargetFile = targetFile;
     TargetFileAttributes = targetFileAttributes;
 }
开发者ID:MisterHoker,项目名称:NetworkLibrary,代码行数:7,代码来源:LoadFileConfiguration.cs

示例15: CreateFile

        public DokanError CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
        {
            info.DeleteOnClose = (options & FileOptions.DeleteOnClose) != 0;
            //Console.WriteLine("CreateFile: {0}, mode = {1}", fileName, mode);

            if (fileName == "\\")
            {
                return DokanError.ErrorSuccess;
            }

            Directory dir = new Directory(Util.GetPathDirectory(fileName));
            if (!dir.Exists())
            {
                return DokanError.ErrorPathNotFound;
            }

            String name = Util.GetPathFileName(fileName);

            if (name.Length == 0)
            {
                return DokanError.ErrorInvalidName;
            }
            if (name.IndexOfAny(Path.GetInvalidFileNameChars()) > -1)
            {
                return DokanError.ErrorInvalidName;
            }

            // dokan API 要求在目标文件是目录时候,设置 info.IsDirectory = true
            if (dir.Contains(name) && (dir.GetItemInfo(name).attribute & FileAttributes.Directory) != 0)
            {
                info.IsDirectory = true;
                return DokanError.ErrorSuccess;
            }

            try
            {
                File f = new File(fileName, mode);
                f.flagDeleteOnClose = info.DeleteOnClose;
                info.Context = f;
            }
            catch (FileNotFoundException)
            {
                return DokanError.ErrorFileNotFound;
            }
            catch (IOException)
            {
                return DokanError.ErrorAlreadyExists;
            }
            catch (NotImplementedException)
            {
                return DokanError.ErrorAccessDenied;
            }
            catch (Exception)
            {
                return DokanError.ErrorError;
            }

            return DokanError.ErrorSuccess;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:59,代码来源:FSDrive.cs


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