File Lister Application
Okie, I was suddenly pissed off at my list of MP3s one day as I have numerous of them that seems to have weird titles! So much so that I thought of writing a simple application that list out all my MP3 files and then filter out those that does not have a proper name to it. How should I do that? Well, that I have not touch yet, currently only started writing the code to recursively list out all the file names of a directory and its subdirectories and its subdirectories' directories....well you get the drill. Anyway, the following is the code for that File Lister application,
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
namespace FileLister
{
class Program
{
static ArrayList outputDirectoriesNFiles = new ArrayList();
static void Main(string[] args)
{
string FILE_PATH = args[0];
ListEverything(FILE_PATH);
foreach (ListName ln in outputDirectoriesNFiles)
Console.WriteLine(ln.ToString());
Console.WriteLine("Total Files: " + outputDirectoriesNFiles.Count);
}
static void ListEverything(string top_dir)
{
ArrayList directoriesNfiles = ListDirectory(top_dir);
foreach (ListName ln in directoriesNfiles)
{
if (ln.isDirectory)
{
ListEverything(ln.pathName);
}
else
outputDirectoriesNFiles.Add(ln);
}
}
static ArrayList ListDirectory(string dir_name)
{
ArrayList directoriesNfiles = new ArrayList();
string[] filenames = Directory.GetFiles(dir_name);
foreach (string fn in filenames)
{
ListName tmp = new ListName(false, fn);
directoriesNfiles.Add(tmp);
}
string[] dirnames = Directory.GetDirectories(dir_name);
foreach (string dn in dirnames)
{
ListName tmpdir = new ListName(true, dn);
directoriesNfiles.Add(tmpdir);
}
return directoriesNfiles;
}
static bool DirectoryExists(ArrayList dirsnfiles)
{
foreach (ListName ln in dirsnfiles)
if (ln.isDirectory)
return true;
return false;
}
}
class ListName
{
public bool isDirectory;
public string pathName;
public ListName(bool isdir, string pthname)
{
this.isDirectory = isdir;
this.pathName = pthname;
}
public override string ToString()
{
if (isDirectory)
return "Directory: " + pathName;
else
return "File Name: " + pathName;
}
}
}
Is this Java or C++.net?
Looks very complicated...
Posted by Leion | 3:52 AM
Hi Leion!
Having fun at aussie?
It's C# by the way ^_^
Posted by sient | 2:15 AM