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