|
|
|
C# WinApp เขียนโค๊ด replace folder เวลา copy/move folder ยังไงครับ |
|
|
|
|
|
|
|
Code (C#)
string fol = System.IO.Path.GetFileName(directoryName_loopVariable);
cri.ForEach((string item) => { fol = fol.Replace(item, "").Trim(); });
fol = System.IO.Path.GetDirectoryName(directoryName_loopVariable) + "\\" + fol;
try
{
System.IO.DirectoryInfo _dirInfo = new System.IO.DirectoryInfo(directoryName_loopVariable);
_dirInfo.MoveTo(fol);
}
catch
{
foreach (string file in System.IO.Directory.GetFiles(directoryName_loopVariable, "*.*"))
{
string _file =fol + "\\" + System.IO.Path.GetFileName(file);
if (System.IO.File.Exists(_file) && _file != file)
{
string stg;
int i = 1;
do
{
stg = System.IO.Path.GetDirectoryName(_file) + "\\" + System.IO.Path.GetFileNameWithoutExtension(_file) + "_" + i + System.IO.Path.GetExtension(_file);
i++;
} while (System.IO.File.Exists(stg));
_file = stg;
}
System.IO.File.Move(file, _file);
System.Threading.Thread.Sleep(10);
}
try { new System.IO.DirectoryInfo(directoryName_loopVariable).Delete(); }catch{}
}
//"Cannot create a file when that file already exists."
ทั้ง copy ทั้ง move อิรุงตุงนุง เลยครับ
แต่เหมือนมันจะลบ โฟลเดอร์เก่าไม่ได้ครับ
System.IO.DirectoryInfo(directoryName_loopVariable).Delete()
|
|
|
|
|
Date :
2015-08-24 18:22:53 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|