Esempio n. 1
0
        /// <summary>
        /// Gets path with unique filename for a new file or directory.
        /// If the specified path is of an existing file or directory, returns path where the filename part is modified like "file 2.txt", "file 3.txt" etc. Else returns unchanged path.
        /// </summary>
        /// <param name="path">Suggested full path.</param>
        /// <param name="isDirectory">The path is for a directory. The number is always appended at the very end, not before .extension.</param>
        public static string MakeUnique(string path, bool isDirectory)
        {
            if (!AFile.ExistsAsAny(path))
            {
                return(path);
            }
            string ext = isDirectory ? null : GetExtension(path, out path);

            for (int i = 2; ; i++)
            {
                var s = path + " " + i + ext;
                if (!AFile.ExistsAsAny(s))
                {
                    return(s);
                }
            }
        }
Esempio n. 2
0
        //Used by Run and RunConsole.
        static string _NormalizeFile(bool runConsole, string file, out bool isFullPath, out bool isShellPath)
        {
            isShellPath = isFullPath = false;
            file        = APath.ExpandEnvVar(file);
            if (file.NE())
            {
                throw new ArgumentException();
            }
            if (runConsole || !(isShellPath = APath.IsShellPath_(file)))
            {
                if (isFullPath = APath.IsFullPath(file))
                {
                    var fl = runConsole ? PNFlags.DontExpandDosPath : PNFlags.DontExpandDosPath | PNFlags.DontPrefixLongPath;
                    file = APath.Normalize_(file, fl, true);

                    //ShellExecuteEx supports long path prefix for exe but not for documents.
                    //Process.Run supports long path prefix, except when the exe is .NET.
                    if (!runConsole)
                    {
                        file = APath.UnprefixLongPath(file);
                    }

                    if (ADisableFsRedirection.IsSystem64PathIn32BitProcess(file) && !AFile.ExistsAsAny(file))
                    {
                        file = ADisableFsRedirection.GetNonRedirectedSystemPath(file);
                    }
                }
                else if (!APath.IsUrl(file))
                {
                    //ShellExecuteEx searches everywhere except in app folder.
                    //Process.Run prefers current directory.
                    var s2 = AFile.SearchPath(file);
                    if (s2 != null)
                    {
                        file       = s2;
                        isFullPath = true;
                    }
                }
            }
            return(file);
        }