01.
public
static
void
ReplaceFileName(
string
Path,
string
Cri, System.Collections.Generic.List<
string
> lst,
bool
chngformFolder =
false
,
bool
delformFolder =
false
,
string
strFnt =
""
,
string
strBck =
""
,
bool
msg =
true
)
02.
{
03.
new
System.Threading.Thread(ReplaceFileName) { IsBackground =
true
}.Start(
new
object
[] { Path, Cri, lst, chngformFolder, delformFolder, strFnt, strBck, msg });
04.
}
05.
public
static
void
ReplaceFileName(
object
obj)
06.
{
07.
DateTime d1 = DateTime.Now;
08.
string
path = (
string
)((
object
[])obj)[0];
09.
string
Exp = (((
string
)((
object
[])obj)[1]).Trim().Length <= 0) ?
"*.*"
:
"*"
+ (
string
)((
object
[])obj)[1] +
"*"
;
10.
System.Collections.Generic.List<
string
> strReplace = (System.Collections.Generic.List<
string
>)((
object
[])obj)[2];
11.
bool
chngformFolder= (
bool
)((
object
[])obj)[3];
12.
bool
delformFolder = (
bool
)((
object
[])obj)[4];
13.
string
strFnt = (
string
)((
object
[])obj)[5];
14.
string
strBck = (
string
)((
object
[])obj)[6];
15.
bool
msg = (
bool
)((
object
[])obj)[7];
16.
17.
System.Collections.Generic.Stack<
string
> stack =
new
System.Collections.Generic.Stack<
string
>();
18.
stack.Push(path);
19.
20.
while
((stack.Count > 0))
21.
{
22.
string
dir = stack.Pop();
23.
foreach
(
string
file
in
System.IO.Directory.GetFiles(dir, Exp))
24.
{
25.
string
_file = System.IO.Path.GetFileNameWithoutExtension(file);
26.
foreach
(
string
str
in
strReplace)
27.
{
28.
_file = _file.Replace(str,
""
).Trim();
29.
}
30.
_file = (chngformFolder !=
true
) ? _file :System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(file)) +
"_"
+ _file;
31.
_file = (strFnt.Trim().Length <= 0) ? _file : strFnt.Trim() + _file;
32.
_file = (strBck.Trim().Length <= 0) ? _file : _file + strBck.Trim();
33.
_file = (delformFolder !=
true
) ? _file : _file.Replace(System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(file)),
""
);
34.
_file = System.IO.Path.GetDirectoryName(file) +
"\\"
+ _file + System.IO.Path.GetExtension(file);
35.
if
(System.IO.File.Exists(_file))
36.
{
37.
string
stg;
38.
int
i = 1;
39.
do
40.
{
41.
stg = System.IO.Path.GetDirectoryName(_file) +
"\\" + System.IO.Path.GetFileNameWithoutExtension(_file) + "
_" + i + System.IO.Path.GetExtension(_file);
42.
i++;
43.
}
while
(System.IO.File.Exists(stg));
44.
_file = stg;
45.
}
46.
try
47.
{System.IO.File.Move(file, _file); }
48.
catch
{}
49.
System.Threading.Thread.Sleep(10);
50.
51.
}
52.
string
directoryName =
null
;
53.
54.
foreach
(
string
directoryName_loopVariable
in
System.IO.Directory.GetDirectories(dir))
55.
{
56.
directoryName = directoryName_loopVariable;
57.
stack.Push(directoryName);
58.
}
59.
System.Threading.Thread.Sleep(10);
60.
}
61.
DateTime d2 = DateTime.Now;
62.
TimeSpan dd = (d2-d1);
63.
if
(msg ==
true
) { MessageBox.Show(
"Complete...\n Time: "
+ dd.TotalSeconds.ToString(
"0.000"
) +
" s"
); }
64.
}