Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,407 members, 7,819,450 topics. Date: Monday, 06 May 2024 at 04:31 PM

C Sharp Questions? Which Guru Can Write This Program??? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / C Sharp Questions? Which Guru Can Write This Program??? (1644 Views)

What Do You Think Of This Program I Wrote / Capture Image From Webcam And Store In Mysql Database From C Sharp Winform / Java Vs C Sharp (2) (3) (4)

(1) (Reply) (Go Down)

C Sharp Questions? Which Guru Can Write This Program??? by maninmood(m): 7:34pm On Jan 03, 2013
1. Full File Listing



2. Filtered File Listing





3. Folder Statistics: Display the following statistics about all the files in the current folder. Do not list any files in this case.
Files in: C:\Windows
Total files: 49
Total size of all files: 7121424 bytes
Largest file: explorer.exe, 2871808 bytes
Average file length: 145335 bytes




4. Quit, to exit the program
After each operation (except 4) is complete wait for the user to press a key to continue, displaying an appropriate message to this effect. After the key press, the program should clear the screen, then return to the welcome message and the user may select another operation.
Re: C Sharp Questions? Which Guru Can Write This Program??? by maninmood(m): 7:37pm On Jan 03, 2013
This is mine though, still struggling 'tryparsing' the int from Console.ReadLine();

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO; //This is added as we were asked to include it on this project
using System.Text;

namespace IntroProgAssignment
{
class Program

{

static void Main()
{
Console.WriteLine(" You are welcome, these are the lists of menu:"wink;
string[] menuLists = new string[4] { "List All Files", " List Filtered Files", "Display Statistics", "Quit"};
for (int ind = 0; ind < menuLists.Length; ind++)
{
Console.WriteLine(" {0}. {1}", ind + 1, menuLists[ind]);
}
Console.WriteLine();

Console.Write(" Enter the number you are accessing:"wink;
string userEntry = Console.ReadLine();
int userInput;
bool isUserInput = int.TryParse(userEntry, out userInput);

switch (userInput)
{
case 1:
FullFileListing();
QuitProgram();
Main();
break;

case 2:
FilteredFileListing();
QuitProgram();
Main();
break;

case 3:
FolderStatistics();
QuitProgram();
Main();
break;

case 4:
QuitProgram();
Main(); // calling main function
break;
default:
{
while (isUserInput == false)
{
Console.WriteLine(" Sorry you need to enter from number 1 to 4"wink;
userEntry = Console.ReadLine();
isUserInput = int.TryParse(userEntry, out userInput);

}


}
break;


}




Console.ReadLine();


}


static void FullFileListing()
{


DirectoryInfo folderInfo = new DirectoryInfo("C:\\Windows"wink;
FileInfo[] files = folderInfo.GetFiles();

for (int index = 0; index < files.Length; index++)
{
Console.WriteLine("{0}. {1} ({2})", index + 1, files[index].Name, files[index].Length);

}

Console.WriteLine();



}

static void FilteredFileListing()
{
DirectoryInfo folderInfo = new DirectoryInfo("C:\\Windows"wink;

Console.WriteLine(" Below are 'exe' files:"wink;
FileInfo[] exeFiles = folderInfo.GetFiles( "*.exe"wink;
for (int i = 0; i < exeFiles.Length; i++)
{
Console.WriteLine( "{0}. {1} ({2})", i + 1, exeFiles[i].Name, exeFiles[i].Length);
}

Console.WriteLine(" Below are 'dll' files:"wink;
FileInfo[] dllFiles = folderInfo.GetFiles("*.dll"wink;
for (int i = 0; i < dllFiles.Length; i++)
{
Console.WriteLine("{0}. {1} ({2})", i + 1, dllFiles[i].Name, dllFiles[i].Length);
}
Console.WriteLine(" Below are 'log' files:"wink;
FileInfo[] logFiles = folderInfo.GetFiles("*.log"wink;
for (int i = 0; i < logFiles.Length; i++)
{
Console.WriteLine("{0}. {1} ({2})", i + 1, logFiles[i].Name, logFiles[i].Length);
}
Console.WriteLine(" Below are 'ini' files:"wink;
FileInfo[] iniFiles = folderInfo.GetFiles("*.ini"wink;
for (int i = 0; i < iniFiles.Length; i++)
{
Console.WriteLine("{0}. {1} ({2})", i + 1, iniFiles[i].Name, iniFiles[i].Length);
}
Console.WriteLine(" Below are 'xml' files:"wink;
FileInfo[] xmlFiles = folderInfo.GetFiles("*.xml"wink;
for (int i = 0; i < xmlFiles.Length; i++)
{
Console.WriteLine("{0}. {1} ({2})", i + 1, xmlFiles[i].Name, xmlFiles[i].Length);
}
Console.WriteLine(" Below are 'prx' files:"wink;
FileInfo[] prxFiles = folderInfo.GetFiles("*.prx"wink;
for (int i = 0; i < prxFiles.Length; i++)
{
Console.WriteLine("{0}. {1} ({2})", i + 1, prxFiles[i].Name, prxFiles[i].Length);
}
Console.WriteLine(" Below are 'manifest' files:"wink;
FileInfo[] manifestFiles = folderInfo.GetFiles("*.manifest"wink;
for (int i = 0; i < manifestFiles.Length; i++)
{
Console.WriteLine("{0}. {1} ({2})", i + 1, manifestFiles[i].Name, manifestFiles[i].Length);
}
Console.WriteLine(" Below are 'bin' files:"wink;
FileInfo[] binFiles = folderInfo.GetFiles("*.bin"wink;
for (int i = 0; i < binFiles.Length; i++)
{
Console.WriteLine("{0}. {1} ({2})", i + 1, binFiles[i].Name, binFiles[i].Length);
}

Console.ReadLine();
}


static void FolderStatistics()
{
DirectoryInfo statisticsInfo= new DirectoryInfo(" C:\\Windows"wink;
FileInfo[] files = statisticsInfo.GetFiles();
Console.WriteLine(" Total files is {0}", files.Length);
Console.ReadLine();



}

static void QuitProgram()
{
Console.WriteLine("Press Y to exit"wink;
string userAnswer = Console.ReadLine().ToUpper();
Console.Clear();

}





}
}





Any better suggestion? wink
Re: C Sharp Questions? Which Guru Can Write This Program??? by maninmood(m): 12:56pm On Jan 04, 2013
Any contribution, pls? sad
Re: C Sharp Questions? Which Guru Can Write This Program??? by DigitalSignal(m): 9:01am On Jan 15, 2013
@OP:
Must it be a guru?
Re: C Sharp Questions? Which Guru Can Write This Program??? by maninmood(m): 12:03am On Jan 20, 2013
DigitalSignal: @OP:
Must it be a guru?

I sorted it out myself. Thanks for your contribution though.

(1) (Reply)

8 Tried And True Tips For Learning To Code / Iphone,ipad And MAC OS App Designers,where Art Thou? / Sql Error Msg 1801, Level 16 During Execution In Ssms

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 18
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.