PDA

View Full Version : سوال: موجود بودن یک فایل در سیستم.



mjzsoft25
دوشنبه 09 مرداد 1391, 12:09 عصر
سلام دوستان می خواستم بدونم که چه جوری میشه چک کرد که یک فایل روی هار هست یا نه.
مثلا New Text Document.txt توی C:\Windows\System32 هست یا نه.:ناراحت:

ali_habibi1384
دوشنبه 09 مرداد 1391, 12:15 عصر
وجود پوشه:


namespace PaintDotNet
{
internal sealed class PaletteCollection
{
public static void EnsurePalettesPathExists()
{
// Set to folder path we must ensure exists.
string palettesPath = PalettesPath;
try
{
// If the directory doesn't exist, create it.
if (!Directory.Exists(palettesPath))
{
Directory.CreateDirectory(palettesPath);
}
}
catch (Exception)
{
// Fail silently
}
}
}
}

وجود فايل:


using System;
using System.IO;

class Program
{
static void Main()
{
// See if this file exists in the SAME DIRECTORY.
if (File.Exists("TextFile1.txt"))
{
Console.WriteLine("The file exists.");
}
// See if this file exists in the C:\ directory. [Note the @]
if (File.Exists(@"C:\tidy.exe"))
{
Console.WriteLine("The file exists.");
}
// See if this file exists in the C:\ directory [Note the '\\' part]
bool exists = File.Exists("C:\\lost.txt");
Console.WriteLine(exists);
}
}

Arash_janusV3
دوشنبه 09 مرداد 1391, 12:15 عصر
برای تشخیص وجود یک فایل (http://barnamenevis.org/showthread.php?346060-%D9%86%DA%A9%D8%AA%D9%87-%D9%87%D8%A7%DB%8C-%D8%B3%DB%8C-%D8%B4%D8%A7%D8%B1%D9%BE-...&p=1540519&viewfull=1#post1540519)

Farshid007
دوشنبه 09 مرداد 1391, 14:26 عصر
واسه بدست اوردن مسیر سیستم هم:
Environment.GetFolderPath(Environment.SpecialFolde r.System)