コード例 #1
0
        /// <summary>
        /// Retrieves all file content as a string from a directory
        /// </summary>
        /// <param name="directoryObject">Directory to retrieve content from</param>
        /// <param name="strFind">Search string to find</param>
        /// <param name="boolRecurse">Flag that determines whether files are retrieved recursively including files from sub-directories</param>
        /// <returns></returns>
        private static string GetFileContentAsString(this DirectoryObject directoryObject, string strFind, bool boolRecurse)
        {
            // Create File List
            FileObjectList files = directoryObject.GetFiles(strFind, boolRecurse);

            // Load All File Content
            files.ForEach(file => file.Content.Load());

            string strContent = String.Join("\r\n", files.Select(file => file.Content.Value).ToArray());

            return(strContent);
        }
コード例 #2
0
        internal static decimal GetSize(this DirectoryObject directoryObject, FileInformation.FileSizeType fileSizeType, bool boolRecurse)
        {
            try
            {
                // Get Directory Files
                FileObjectList listFiles = directoryObject.GetFiles(boolRecurse);

                // Get Total Size
                decimal decDirectorySize = listFiles.Select(file => (
                                                                (fileSizeType == FileInformation.FileSizeType.Bytes) ? file.Size.Bytes :
                                                                (fileSizeType == FileInformation.FileSizeType.KiloBytes) ? file.Size.KiloBytes :
                                                                (fileSizeType == FileInformation.FileSizeType.MegaBytes) ? file.Size.MegaBytes :
                                                                (fileSizeType == FileInformation.FileSizeType.GigaBytes) ? file.Size.GigaBytes : 0)).Sum();

                return(decDirectorySize);
            }
            catch (Exception ex)
            {
                // To Be Implemented: Throw Custom Exception...
                Console.WriteLine(ex.ToString());
                return(-1);
            }
        }