DirectoryInfo dir = new DirectoryInfo(s)


Download 16.93 Kb.
Sana05.01.2022
Hajmi16.93 Kb.
#214046
Bog'liq
File bilan ishlash


// 1.
//string s = @"C:\temp";

//DirectoryInfo dir = new DirectoryInfo(s);

//dir.Create();

//dir.CreateSubdirectory("txt");

//dir.CreateSubdirectory(@"txt\t");

//2

//string s2 = @"D:\";

//DirectoryInfo d = new DirectoryInfo(s2);

//DirectoryInfo [] files = d.GetDirectories();

//Console.WriteLine("Filelar soni " + files.Length);

//foreach (DirectoryInfo file in files)

//{

// Console.WriteLine("------------------------------------");

// Console.WriteLine("File_name" + file.FullName);
// Console.WriteLine("File_atributs" + file.Attributes);

// Console.WriteLine("File_data" + file.CreationTime);

// Console.WriteLine("------------------------------------");

//}

//3

////Filelar bilan ishlash
// string s3 = @"C:\temp\txt\t\satr.txt";

// FileInfo file1 = new FileInfo(s3);

//// file1.Create();

//4

// //file1.Delete();

//5

// StreamWriter writer = file1.CreateText();

// writer.WriteLine("Ozoda");

// //writer.WriteLine(writer.NewLine);

// writer.WriteLine("Ziyoda");

// writer.Close();

// writer.Dispose();

//6

//string path = @"C:\temp\txt\t\satr.txt";

//FileInfo file1 = new FileInfo(path);

//StreamReader str = file1.OpenText();

//string satr = null;

//while ((satr = str.ReadLine()) != null)

//{

// Console.WriteLine(satr);

//}
//Console.ReadKey();

//7

//using (StreamReader read1 = new StreamReader(s3, true))

//{

// string alltext = read1.ReadToEnd();

// Console.Write(alltext);
//}

//Console.ReadKey();

//8

//int n, m, k;

//Console.WriteLine("massiv o'lchami");

//n = int.Parse(Console.ReadLine());

//m = int.Parse(Console.ReadLine());

//int[,] mtr;
//mtr = new int[n, m];
////int h;

//for (int i = 0; i < n; i++)

//{

// for (int j = 0; j < m; j++)

// {

// Console.Write("a[{0},{1}]=", i, j);

// mtr[i, j] = int.Parse(Console.ReadLine());

// }

//}
//9

//using (StreamWriter sw = new StreamWriter(@"D:\text.doc"))

//{

// for (int i = 0; i < mtr.GetLength(0); i++)

// {

// for (int j = 0; j < mtr.GetLength(1); j++)

// {

//sw.Write(mtr[i, j]);

//sw.Write(' ');

// }

// sw.WriteLine();

// }
//}

//10

//string a = @"D:\text.doc";

//string s = null;

//using (StreamReader str = new StreamReader(a))

//{
// s = s + str.ReadToEnd();


// }

//Console.WriteLine(s);

//int n = 5;

//int[] a = new int[n];

//for (int i = 0; i < n; i++)

// a[i] = int.Parse(Console.ReadLine());
// string path = @"C:\temp\massiv.doc";

//using (StreamWriter stw = new StreamWriter(path))

//{

// for (int i = 0; i < n; i++)

// stw.WriteLine(a[i]);

//}

//int s=0;

//using(StreamReader str=new StreamReader(path))

//{

// while(str.Peek() >=0 )

// {

// int a= int.Parse(str.ReadLine());

// if(a>0)

//Console.WriteLine(a);

// }



//}

//Console.WriteLine(s);
//FileInfo fi=new FileInfo(@"C:\temp\bin.dat");
//using(BinaryWriter bn=new BinaryWriter(fi.OpenWrite()))

//{

// bn.Write(23);

//}

//using (BinaryReader bn = new BinaryReader(fi.OpenRead()))

//{

// Console.WriteLine(bn.ReadInt16());

//}

//--------------------------------------------------------------

//string filename = @"c:\Users\asus\Documents\doc.txt";

//Stream f = File.Open(filename, FileMode.Create);

//StreamWriter writer = new StreamWriter(f);

//char simvol;

//do{

// simvol=(char)Console.Read();



// writer.Write(simvol);

//}


//while(simvol!='.');

//writer.Close();

// f= File.Open(filename, FileMode.Open);

//StreamReader reader = new StreamReader(f);

////string line = reader.ReadLine();

////Console.WriteLine(line);

////string line_end = reader.ReadToEnd();

////Console.WriteLine(line_end);

//for (string line = reader.ReadLine(); line != null; line=reader.ReadLine() )

//{


// Console.WriteLine(line);

//}


// reader.Close();

//-----------------------------------------------------------------------

//Comanda straka bilan ishlash

//foreach(string s in args)

//{

// Console.WriteLine(s);



//}

//--------------------------------------------------------------------

//string filename;

//if (args.Length == 0)

//{

// Console.WriteLine("Enter file name ");



// //Console.WriteLine("you must enter file name");

// //return;

// filename = Console.ReadLine();

//}


//else

//{


// filename = args[0];

//}
////for(int i=0; i

////{

//// Console.WriteLine(args[i]);



////}
//if (!File.Exists(args[0]))

//{


// Console.WriteLine("File not found");

// Console.ReadKey();

// return;

//}


//StreamReader reader = new StreamReader(filename);

//Console.WriteLine(reader.ReadToEnd());

//--------------------------------------------------------------------

//int s=0;

//for(int i=0; i

//{


// s +=int.Parse(args[i]);

//}


//Console.WriteLine(s);

//------------------------------------------------------------

string filname="untitled.txt";

string in_file="";

if(args.Length!=0)

{

Console.Write("Enter file name: ");



filname = args[0];

}
Console.WriteLine("If you want to exit enter:q");

if(File.Exists(filname))

{

StreamReader reading = new StreamReader(File.OpenRead(filname));



in_file=reading.ReadToEnd();

reading.Close();

Console.WriteLine(in_file);

}

string text = "";



string in_console;

while(!(in_console=Console.ReadLine()).Equals(":q")) //equals=>qatorni solishtiradi

{

text += in_console+"\n";


}

Console.WriteLine("Do you want to save(yes/no)?");

string answer = Console.ReadLine();

Console.WriteLine(answer);

if(answer.ToLower().Equals("yes"))

{

StreamWriter writing = new StreamWriter(File.Create(filname));



writing.Write(in_file+"\t");

writing.Write(text);

writing.Close();

}

//int n = 100;



// // File.Delete(@"d:\HMX\task_110290" + i + ".doc");

//File.Create(@"c:\Users\asus\Desktop\Сon.css");

char simvol,simvol1;

string s=null,s1,s2;

Console.WriteLine("Qaysi simvolgacha fayllga yozsin");

simvol1 = (char)Console.Read();

do

{

simvol = (char)Console.Read();



s+=simvol;

}

while (simvol != simvol1);



Console.WriteLine("Faylga kiritilgan ma'lumotni yozasizmi? ");

Console.ReadLine();

s1 = Console.ReadLine();

Console.WriteLine(s1);

if (s1.ToUpper() == "yes" || s1 == "yes")

{

Console.WriteLine("Faylni yo'lini ko'rsating");



s2 = Console.ReadLine();

StreamWriter writer = new StreamWriter(File.Open(s2, FileMode.Create));

writer.Write(s);

writer.Close();

}

else if(s1=="no" || s1=="" || s1.ToUpper()=="no")



{

StreamWriter writer = new StreamWriter(File.Open(@"c:\Users\asus\Documents\doc.txt", FileMode.Create));

writer.Write(simvol);

writer.Close();



}
Download 16.93 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling