blob: f9d98e0a5a7a8b7603b5a52a41933e80fcce2956 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FileHelper.cs" company="HandBrake Project (http://handbrake.fr)">
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
// Helper methods for dealing with files.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Helpers
{
using System;
using System.IO;
/// <summary>
/// Helper methods for dealing with files.
/// </summary>
public class FileHelper
{
/// <summary>
/// The file path has invalid chars.
/// </summary>
/// <param name="path">
/// The path.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public static bool FilePathHasInvalidChars(string path)
{
bool result = false;
if (!string.IsNullOrEmpty(path))
{
try
{
string file = Path.GetFileNameWithoutExtension(path);
string directory = Path.GetDirectoryName(path);
if (path.Split(':').Length - 1 > 1)
{
return true;
}
if (!string.IsNullOrEmpty(file) && file.Replace("\"", string.Empty).IndexOfAny(Path.GetInvalidPathChars()) != -1)
{
return true;
}
if (!string.IsNullOrEmpty(directory) && directory.Replace("\"", string.Empty).IndexOfAny(Path.GetInvalidPathChars()) != -1)
{
return true;
}
}
catch (ArgumentException)
{
result = true;
}
}
return result;
}
}
}
|