1
// ------------------------------------------------------------------
2 // Copyright (C) 2011-2015 Maruko Toolbox Project
4 // Authors: LYF <lyfjxymf@sina.com>
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
10 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
15 // express or implied.
16 // See the License for the specific language governing permissions
17 // and limitations under the License.
18 // -------------------------------------------------------------------
22 using System
.Collections
.Generic
;
25 using System
.Diagnostics
;
26 using System
.Windows
.Forms
;
28 using System
.Threading
;
38 /// <param name="path"></param>
39 /// <returns></returns>
40 public static string FormatPath(string path
)
42 if (string.IsNullOrEmpty(path
)) { return null; }
44 ret
= path
.Replace("\"", "");
45 if (ret
.Contains(" ")) { ret = "\"" + ret + "\""; }
50 /// concat:D:\一二三123.png 可以防止FFMpeg不认中文名输入文件的Bug
52 /// <param name="path"></param>
53 /// <returns></returns>
54 public static string ConcatProtocol(string path
)
56 return FormatPath("concat:" + path
);
62 /// <param name="oriPath_">原路径</param>
63 /// <returns>不会重名的路径</returns>
64 public static string GetSuitablePath(string oriPath_
)
66 if (string.IsNullOrEmpty(oriPath_
)) { return null; }
67 string oriPath
= oriPath_
.Replace("\"", string.Empty
);//去掉引号
69 if ((!File
.Exists(oriPath
)) && (!Directory
.Exists(oriPath
)))
74 string ext
= Path
.GetExtension(oriPath
);
75 string str
= oriPath
.Remove(oriPath
.Length
- ext
.Length
) + "_" + i
;
76 while (File
.Exists(str
+ ext
) || Directory
.Exists(str
+ ext
))
79 str
= oriPath
+ "_" + i
;
85 /// <para></para>输入:目标文件的 路径或所在目录;
86 /// <para></para>输入:原始文件的路径;
87 /// <para></para>输出:输出文件的路径。
88 /// <para></para>用目标目录或文件路径(取自tbOutput),和输入的文件,返回一个供输出的文件路径。
90 /// <param name="DestDirOrFile_">目标目录或文件路径</param>
91 /// <param name="SrcFile_">输入的文件(若DestDirOrFile是文件,则忽略此项)</param>
92 /// <param name="dotExtension">换扩展名</param>
93 /// <returns></returns>
94 public static string GetSimilarFilePath(string DestDirOrFile_
, string SrcFile_
, string dotExtension
)
96 if (string.IsNullOrEmpty(DestDirOrFile_
)) { return null; }
97 if (string.IsNullOrEmpty(SrcFile_
)) { return null; }
98 string DestDirOrFile
= DestDirOrFile_
.Replace("\"", string.Empty
);
99 string SrcFile
= SrcFile_
.Replace("\"", string.Empty
);//去掉引号
101 if (DestDirOrFile
.EndsWith("\\"))//目录
103 if (string.IsNullOrEmpty(dotExtension
))//没有指定扩展名
105 return DestDirOrFile
+ Path
.GetFileName(SrcFile
);
109 return DestDirOrFile
+ Path
.GetFileNameWithoutExtension(SrcFile
) + dotExtension
;
117 if (string.IsNullOrEmpty(dotExtension
))//没有指定扩展名
119 return DestDirOrFile
;
123 return ChangeExt(DestDirOrFile
, dotExtension
);//换扩展名
128 /// 用目标目录或文件路径(取自tbOutput),和输入的文件,返回一个供输出的文件路径。
130 /// <param name="DestDirOrFile">目标目录或文件路径</param>
131 /// <param name="SrcFile">输入的文件</param>
132 /// <returns></returns>
133 public static string GetSimilarFilePath(string DestDirOrFile
, string SrcFile
)
135 return GetSimilarFilePath(DestDirOrFile
, SrcFile
, null);
140 /// <param name="srcFile"></param>
141 /// <param name="ext"></param>
142 /// <returns></returns>
143 public static string ChangeExt(string srcFile
, string ext
)
145 return GetDir(srcFile
) + Path
.GetFileNameWithoutExtension(srcFile
) + ext
;
150 /// <param name="path">文件路径</param>
151 /// <returns></returns>
152 public static string GetDir(string path
)
154 string fileDir
= Path
.GetDirectoryName(path
);
155 if (fileDir
.EndsWith("\\"))
161 return fileDir
+ "\\";