本文整理汇总了C#中FileInfo类的典型用法代码示例。如果您正苦于以下问题:C# FileInfo类的具体用法?C# FileInfo怎么用?C# FileInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileInfo类属于命名空间,在下文中一共展示了FileInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadExcel
public static Excel LoadExcel(string path)
{
FileInfo file = new FileInfo(path);
ExcelPackage ep = new ExcelPackage(file);
Excel xls = new Excel(ep.Workbook);
return xls;
}
示例2: GetDirectoryPath
// Ex: C:\Users\Public\Test\blah.txt would return C:\Users\Public\Test\
public static string GetDirectoryPath(string filePath)
{
if(string.IsNullOrEmpty(filePath)) return "";
FileInfo fileInfo = new FileInfo(filePath);
return (fileInfo != null) ? fileInfo.Directory.FullName : "";
}
示例3: FalseForDirectory
public void FalseForDirectory()
{
string fileName = GetTestFilePath();
Directory.CreateDirectory(fileName);
FileInfo di = new FileInfo(fileName);
Assert.False(di.Exists);
}
示例4: CopyFile
static void CopyFile(string filename, string outputfilename, string pathToBuiltProject) {
string strCWD = Directory.GetCurrentDirectory();
string strSource = Path.Combine(Path.Combine(strCWD, SteamAPIRelativeLoc), filename);
string strFileDest = Path.Combine(Path.GetDirectoryName(pathToBuiltProject), outputfilename);
if (!File.Exists(strSource)) {
Debug.LogWarning(string.Format("[Steamworks.NET] Could not copy {0} into the project root. {0} could not be found in '{1}'. Place {0} from the redist into the project root manually.", filename, SteamAPIRelativeLoc));
return;
}
if (File.Exists(strFileDest)) {
if (File.GetLastWriteTime(strSource) == File.GetLastWriteTime(strFileDest)) {
FileInfo fInfo = new FileInfo(strSource);
FileInfo fInfo2 = new FileInfo(strFileDest);
if (fInfo.Length == fInfo2.Length) {
return;
}
}
}
File.Copy(strSource, strFileDest, true);
if (!File.Exists(strFileDest)) {
Debug.LogWarning(string.Format("[Steamworks.NET] Could not copy {0} into the built project. File.Copy() Failed. Place {0} from the redist folder into the output dir manually.", filename));
}
}
示例5: Parse
public static Package Parse(FileInfo assemblyInfoFile)
{
try
{
var lines = Storage.ReadAllLines(assemblyInfoFile.FullName);
var title = AssemblyInfo.GetData(lines, AssemblyInfoData.AssemblyTitle);
var projectFile = assemblyInfoFile.Directory.Parent.GetFiles(title + "*.csproj").SingleOrDefault();
if (projectFile == null)
{
return null;
}
var targetFramework = ExtractTargetFramework(projectFile);
var version = AssemblyInfo.GetData(lines, AssemblyInfoData.AssemblyVersion);
var nuspec = projectFile.Directory.GetFiles("Package.nuspec").SingleOrDefault();
if (nuspec == null)
{
return new Package(projectFile, assemblyInfoFile, lines, title, version, targetFramework);
}
return new Package(projectFile, assemblyInfoFile, lines, title, version, targetFramework, nuspec);
}
catch (Exception exception)
{
throw new IOException($"Cannot parse the file {assemblyInfoFile.FullName}.", exception);
}
}
示例6: Create
// ------------------------------------------------------------------
// Desc:
// ------------------------------------------------------------------
public static exTimebasedCurveInfo Create( string _path, string _name )
{
//
if ( new DirectoryInfo(_path).Exists == false ) {
Debug.LogError ( "can't create asset, path not found" );
return null;
}
if ( string.IsNullOrEmpty(_name) ) {
Debug.LogError ( "can't create asset, the name is empty" );
return null;
}
string assetPath = Path.Combine( _path, _name + ".asset" );
// check if create the asset
FileInfo fileInfo = new FileInfo(assetPath);
if ( fileInfo.Exists ) {
if ( EditorUtility.DisplayDialog( _name + " already exists.",
"Do you want to overwrite the old one?",
"Yes",
"No" ) == false )
{
return null;
}
}
//
exTimebasedCurveInfo newCurve = ScriptableObject.CreateInstance<exTimebasedCurveInfo>();
AssetDatabase.CreateAsset(newCurve, assetPath);
Selection.activeObject = newCurve;
return newCurve;
}
示例7: Start
void Start()
{
triviaFile = new FileInfo(Application.dataPath + "/trivia.txt");
if (triviaFile != null && triviaFile.Exists) {
reader = triviaFile.OpenText();
} else {
embedded = (TextAsset) Resources.Load("trivia_embedded", typeof (TextAsset));
reader = new StringReader(embedded.text);
}
string lineOfText = "";
int lineNumber = 0;
while ( ( lineOfText = reader.ReadLine() ) != null ) {
string question = lineOfText;
int answerCount = Convert.ToInt32(reader.ReadLine());
List<string> answers = new List<string>();
for (int i = 0; i < answerCount; i++) {
answers.Add(reader.ReadLine());
}
Trivia temp = new Trivia(question, answerCount, answers);
triviaQuestions.Add(temp);
lineNumber++;
}
SendMessage( "BeginGame" );
}
示例8: IsFileLocked
protected static bool IsFileLocked(string fullPath)
{
FileInfo file = new FileInfo(fullPath);
FileStream stream = null;
try
{
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
}
finally
{
if (stream != null)
stream.Close();
}
//file is not locked
return false;
}
示例9: Slice
static void Slice(string sourceFile, string destinationDirectory, int parts)
{
string extension = new FileInfo(sourceFile).Extension;
ext = extension;
using (var source = new FileStream(destinationDirectory + sourceFile, FileMode.Open))
{
int pieceSize = (int)Math.Ceiling((decimal)source.Length / parts);
byte[] buffer = new byte[4096];
for (int i = 1; i <= parts; i++)
{
string currentFilePath = string.Format(destinationDirectory + "part" + i + extension);
using (var destination =
new FileStream(currentFilePath, FileMode.Create))
{
long partBytes = 0;
while (partBytes < pieceSize)
{
int readBytes = source.Read(buffer, 0, buffer.Length);
if (readBytes == 0)
{
break;;
}
destination.Write(buffer, 0, readBytes);
partBytes += readBytes;
}
}
slicedFiles.Add(currentFilePath);
}
}
}
示例10: StartProcess
/// <summary>
/// プロセスを実行
/// </summary>
public void StartProcess(ProcessData procData)
{
if(procData.use && !procData.IsRunning)
{
FileInfo fileInfo = new FileInfo(procData.exePath);
if(fileInfo.Exists)
{
Process proc = new Process();
proc.StartInfo.FileName = Path.GetFullPath(procData.exePath);
//引数設定
if(procData.argument != "")
proc.StartInfo.Arguments = procData.argument;
//ウィンドウスタイル設定
if(!ApplicationSetting.Instance.GetBool("IsDebug"))
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
try
{
proc.Start();
processList.Add(proc);
procData.IsRunning = true;
}
catch(Exception e)
{
UnityEngine.Debug.Log("ExternalProcess :: process start error - " + e.Message);
}
}
}
}
示例11: WithNoWeaving
public void WithNoWeaving()
{
var sourceProjectFile = new FileInfo(@"TestProjects\ProjectWithNoWeaving.csproj");
var targetFileInfo = sourceProjectFile.CopyTo(sourceProjectFile.FullName + "ProjectReaderTest", true);
try
{
var reader = new ProjectReader(targetFileInfo.FullName);
Assert.IsNull(reader.DependenciesDirectory);
Assert.IsNull(reader.ToolsDirectory);
Assert.IsNull(reader.CheckForEquality);
Assert.IsNull(reader.CheckForIsChanged);
Assert.IsNull(reader.ProcessFields);
Assert.IsNull(reader.MessageImportance);
Assert.IsNull(reader.TryToWeaveAllTypes);
Assert.IsNull(reader.EventInvokerName);
Assert.IsNull(reader.EventInvokerName);
Assert.IsNull(reader.TargetPath);
Assert.IsNull(reader.TargetNode);
Assert.IsNull(reader.DependenciesDirectory);
}
finally
{
targetFileInfo.Delete();
}
}
示例12: Start
// Use this for initialization
void Start()
{
FileStream file = null;
FileInfo fileInfo = null;
try
{
fileInfo = new FileInfo("file.txt");
file = fileInfo.OpenWrite();
for(int i = 0; i < 255; i++)
{
file.WriteByte((byte)i);
}
throw new ArgumentNullException("Something bad happened.");
}
catch(UnauthorizedAccessException e)
{
Debug.LogWarning(e.Message);
}
catch (ArgumentNullException e)
{
//Debug.LogWarning(e.Message);
Debug.LogWarning("BAD!!!");
}
finally
{
if (file != null)
file.Close();
}
}
示例13: EvaluateRelativePath
/// <summary>
/// Evaluates and provides the relative path.
/// </summary>
/// <param name="mainDirPath">The source, or starting location.</param>
/// <param name="absoluteFilePath">The location to find.</param>
/// <returns></returns>
public static string EvaluateRelativePath(this FileInfo mainDirPath, FileInfo absoluteFilePath)
{
string[] firstPathParts = mainDirPath.FullName.Trim(Path.DirectorySeparatorChar).Split(Path.DirectorySeparatorChar);
string[] secondPathParts = absoluteFilePath.FullName.Trim(Path.DirectorySeparatorChar).Split(Path.DirectorySeparatorChar);
int sameCounter = 0;
for (int i = 0; i < Math.Min(firstPathParts.Length, secondPathParts.Length); i++)
{
if (!firstPathParts[i].ToLower().Equals(secondPathParts[i].ToLower()))
break;
sameCounter++;
}
if (sameCounter == 0)
return absoluteFilePath.FullName;
string newPath = String.Empty;
for (int i = sameCounter; i < firstPathParts.Length; i++)
{
if (i > sameCounter)
newPath += Path.DirectorySeparatorChar;
newPath += "..";
}
for (int i = sameCounter; i < secondPathParts.Length; i++)
{
newPath = String.Format("{0}{1}{2}", newPath, Path.DirectorySeparatorChar, secondPathParts[i]);
}
return newPath;
}
示例14: FindLargeFiles
public void FindLargeFiles(List<string> AllowedExtensions, long MinSize)
{
foreach (string Filename in Manifest)
{
FileInfo FI = new FileInfo(Filename);
long Size = FI.Length;
if (Size > MinSize)
{
bool bAllowed = false;
foreach (string Extension in AllowedExtensions)
{
if (Filename.EndsWith(Extension, StringComparison.InvariantCultureIgnoreCase))
{
bAllowed = true;
break;
}
}
if (!bAllowed)
{
CommandUtils.LogWarning("{0} is {1} with an unexpected extension", Filename, AnalyzeThirdPartyLibs.ToMegabytes(Size));
}
}
}
}
示例15: Start
public object Start(string level)
{
LocalNode node = new LocalNode(Assembly.GetExecutingAssembly());
node.Join();
try
{
FileInfo levelInfo = new FileInfo(level);
if (levelInfo.Directory.Name != "Resources")
return "Level is not in a resources directory.";
DirectoryInfo directoryInfo = levelInfo.Directory.Parent;
World.BaseDirectory = directoryInfo.FullName;
World.RuntimeDirectory = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName;
using (RuntimeGame game = new RuntimeGame(levelInfo.Name.Substring(0, levelInfo.Name.Length - levelInfo.Extension.Length)))
{
game.Run();
}
}
finally
{
node.Leave();
}
return null;
}