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


C# FileSystemInfo.GetType方法代码示例

本文整理汇总了C#中System.IO.FileSystemInfo.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# FileSystemInfo.GetType方法的具体用法?C# FileSystemInfo.GetType怎么用?C# FileSystemInfo.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileSystemInfo的用法示例。


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

示例1: GetSize

        public static long GetSize(FileSystemInfo fsi)
        {
            Exceptions.CheckArgumentNull(fsi, "fsi");

            try
            {
                FileInfo fileInfo = fsi as FileInfo;
                if (fileInfo != null)
                    return fileInfo.Length;

                DirectoryInfo directoryInfo = fsi as DirectoryInfo;
                if (directoryInfo != null)
                    return directoryInfo.EnumerateFiles("*", SearchOption.AllDirectories).Sum(f => f.Length);

                Log.Warning("[FileEx]Неизвестный наследник FileSystemInfo: {0}", fsi.GetType());
                return 0;
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "[FileEx]Непредвиденная ошибка.");
                return 0;
            }
        }
开发者ID:kidaa,项目名称:Pulse,代码行数:23,代码来源:FileEx.cs

示例2: Upload

        /// <summary>
        /// Uploads the specified file or directory to the remote host.
        /// </summary>
        /// <param name="fileInfo">Local file to upload.</param>
        /// <param name="filename">Remote host file name.</param>
        /// <exception cref="ArgumentNullException"><paramref name="fileInfo"/> or <paramref name="filename"/> is null.</exception>
        public void Upload(FileSystemInfo fileSystemInfo, string path)
        {
            if (fileSystemInfo == null)
                throw new ArgumentNullException("fileSystemInfo");

            if (string.IsNullOrEmpty(path))
                throw new ArgumentException("path");

            using (var input = new PipeStream())
            using (var channel = this.Session.CreateChannel<ChannelSession>())
            {
                channel.DataReceived += delegate(object sender, Common.ChannelDataEventArgs e)
                {
                    input.Write(e.Data, 0, e.Data.Length);
                    input.Flush();
                };

                channel.Open();

                var pathParts = path.Split('\\', '/');

                //  Send channel command request
                channel.SendExecRequest(string.Format("scp -rt \"{0}\"", pathParts[0]));
                this.CheckReturnCode(input);

                //  Prepare directory structure
                for (int i = 0; i < pathParts.Length - 1; i++)
                {
                    this.InternalSetTimestamp(channel, input, fileSystemInfo.LastWriteTimeUtc, fileSystemInfo.LastAccessTimeUtc);
                    this.SendData(channel, string.Format("D0755 0 {0}\n", pathParts[i]));
                    this.CheckReturnCode(input);
                }

                if (fileSystemInfo is FileInfo)
                {
                    this.InternalUpload(channel, input, fileSystemInfo as FileInfo, pathParts.Last());
                }
                else if (fileSystemInfo is DirectoryInfo)
                {
                    this.InternalUpload(channel, input, fileSystemInfo as DirectoryInfo, pathParts.Last());
                }
                else
                {
                    throw new NotSupportedException(string.Format("Type '{0}' is not supported.", fileSystemInfo.GetType().FullName));
                }

                //  Finish directory structure
                for (int i = 0; i < pathParts.Length - 1; i++)
                {
                    this.SendData(channel, "E\n");
                    this.CheckReturnCode(input);
                }

                channel.Close();
            }
        }
开发者ID:keyanmca,项目名称:ch4zilla,代码行数:62,代码来源:ScpClient.NET.cs

示例3: GetKey

        /// <summary>
        /// Get image key for given folder of file
        /// </summary>
        /// <param name="info">FileInfo for a file or DirectoryInfo for directory</param>
        /// <returns>Image keys from imagelist1</returns>
        private string GetKey(FileSystemInfo info)
        {
            string key = info.Name.ToLower();
            try { if (imageList1.Images.ContainsKey(key)) return key; }
            catch { }

            key = info.Extension.ToLower();
            try { if (imageList1.Images.ContainsKey(key)) return key; }
            catch { }

            if (info.GetType() == typeof(FileInfo)) return "file";

            string name = info.FullName.Substring(RegistryAccess.CodesPath.Length + 1);
            if (!name.StartsWith("Volume"))
            {
                if (name.Contains(Path.DirectorySeparatorChar.ToString())) return key = "folder";
                return "root";
            }

            if (name.Contains(Path.DirectorySeparatorChar.ToString())) return "problem";
            return "volume";
        }
开发者ID:nocmnt,项目名称:UVA-Arena,代码行数:27,代码来源:CodesBrowser.cs

示例4: Scan

		/// <summary>
		/// Scan a FileSystem object (file or directory) with optional recursion.
		/// </summary>
		/// <param name="file">FileSystem object to scan</param>
		/// <param name="recurse">Recurse when true if FileSystem object is a directory. Otherwise this argument is ignored..</param>
		public override void Scan(FileSystemInfo file, bool recurse)
		{
			if( file!=null) 
			{
				if(file is FileInfo)
					Scan(file as FileInfo);
				else if (file is DirectoryInfo)
					Scan(file as DirectoryInfo, recurse);
				else
					throw new NotSupportedException( string.Format(  CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString(STR_SCAN_FILESYSTEMINFO_NONT_SUPPORTED), file.GetType() ) );
			}
		}
开发者ID:WolfeReiter,项目名称:clamav-csharp-client,代码行数:17,代码来源:ClamdStreamAgent.cs

示例5: AppendCvs

        /// <summary>
        /// Checks the end of a path string, if the path ends in CVS it does nothing, 
        /// otherwise it appends CVS to the full path.
        /// </summary>
        /// <param name="fs">Full path to a file/ directory that may or may
        ///     not end with CVS.</param>
        /// <returns>The full path with a CVS appended.</returns>
        public static FileSystemInfo AppendCvs(FileSystemInfo fs) {
            if (fs.FullName.EndsWith(string.Format("{0}{1}{2}", Path.DirectorySeparatorChar, CVS, Path.DirectorySeparatorChar)) ||
                fs.FullName.EndsWith(string.Format("{0}{1}", Path.DirectorySeparatorChar, CVS)) ||
                PathTranslator.IsCvsDir(fs.FullName)) {
                LOGGER.Warn(string.Format("Already ends with cvs directory: {0}",
                    fs.FullName));
                return fs;
            } 

            if (fs.GetType() == typeof(DirectoryInfo)) {
                return new DirectoryInfo(Path.Combine(fs.FullName, CVS));
            } else {
                return new FileInfo(Path.Combine(fs.FullName, CVS));
            }
        }
开发者ID:Orvid,项目名称:NAntUniversalTasks,代码行数:22,代码来源:PathTranslator.cs


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