Пример #1
0
        /// <summary>
        /// Get a child file under the given directory (<paramref name="a_directory"/>) with the given name (<paramref name="a_fileName"/>).
        /// </summary>
        /// <param name="a_directory">"This" directory.</param>
        /// <param name="a_fileName">File name.</param>
        /// <returns>File path to the child file.</returns>
        /// <exception cref="NullReferenceException">Thrown if <paramref name="a_directory"/> is null.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_fileName"/> is null.</exception>
        public static string FilePath(this DirectoryInfo a_directory, string a_fileName)
        {
            #region Argument Validation

            if (a_directory == null)
            {
                throw new NullReferenceException(nameof(a_directory));
            }

            if (a_fileName == null)
            {
                throw new ArgumentNullException(nameof(a_fileName));
            }

            #endregion

            return(PathBuilder.Create(a_directory.FullName).Child(a_fileName));
        }
Пример #2
0
        /// <summary>
        /// Create a file that is this file but with the given extension (<paramref name="a_extension"/>).
        /// </summary>
        /// <param name="a_extension">New extension.</param>
        /// <returns>Created file with the new extension.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_extension"/> is null.</exception>
        public IFile ChangeExtension(string a_extension)
        {
            #region Argument Validation

            if (a_extension == null)
            {
                throw new ArgumentNullException(nameof(a_extension));
            }

            #endregion

            var extension = a_extension.TrimStart('.');

            var path    = TargetFile.FullName;
            var newName = PathBuilder.Create(path).NameWithoutExtension() + "." + extension;
            var newPath = PathBuilder.Create(path).Parent().Child(newName);

            return(new FsFile(newPath));
        }
Пример #3
0
 /// <summary>
 /// Get the file path for a file with the given name (<paramref name="a_name"/>) or relative path under this directory.
 /// </summary>
 /// <param name="a_name">File name or relative path.</param>
 /// <returns>File path.</returns>
 public PathBuilder FilePath(string a_name)
 {
     return(PathBuilder.Create(TargetDirectory.FilePath(a_name)));
 }