Ejemplo n.º 1
0
        private string FormatAttributes(FileAttribute attributes)
        {
            string attrStr = "";

            if (attributes.HasFlag(FileAttribute.Archive))
            {
                attrStr += "A";
            }
            else if (attributes.HasFlag(FileAttribute.Directory))
            {
                attrStr += "D";
            }
            else if (attributes.HasFlag(FileAttribute.Hidden))
            {
                attrStr += "H";
            }
            else if (attributes.HasFlag(FileAttribute.ReadOnly))
            {
                attrStr += "R";
            }
            else if (attributes.HasFlag(FileAttribute.System))
            {
                attrStr += "S";
            }

            return(attrStr);
        }
Ejemplo n.º 2
0
        public static string Dir(string PathName, FileAttribute Attributes = FileAttribute.Normal)
        {
            if (Attributes.HasFlag(FileAttribute.Volume))
            {
                throw new NotSupportedException("FileAttribute.Volume");
            }

            if (Attributes.HasFlag(FileAttribute.Directory))
            {
                if (Directory.Exists(PathName))
                {
                    return(new DirectoryInfo(PathName).ToString());
                }
            }
            if (File.Exists(PathName))
            {
                return(new FileInfo(PathName).ToString());
            }
            return("");
        }