Ok, first things first. Hello everyone, I have a question.
How would I go about adding Shortcut Arguments to my program(Code shown below).
My idea:
I play a game called Counter-Strike:Source and recently I've needed to gather all the names of custom maps added to the \map
directory. To the point. I've created this program to read files with the extension of ".txt". While creating this program I thought why not try learning how to create Shortcut Arguments. What I mean by this is when you create a shortcut to any program a file gets created( a ".lnk" file) and we all know what this file does(points to the file of which was linked). Now with some programs they allow the use of Arguments. Here I show an example:
Before any arguments:
Target: "C:\Program Files\Mozilla Firefox\firefox.exe"
After:
Target: "C:\Program Files\Mozilla Firefox\firefox.exe" -txt
Now I doubt that this will change anything with firefox but I would like to add something that allows the usage of arguments.
Lets say if I wanted to get a list of all the files that had the extension ".123" I would add -123 to the end of the Target: in my programs shortcut properties.
Anyways I did my best to be as clear as I possibly could if you need a further explanation please let me know and I'll see what I can do to explain it further.
Thanks in advance. - Poab9200
using System;
using System.IO;
namespace LoopThroughFiles
{
public class Program
{
public static void Main(string[] args)
{
Console.Title = "Loop Trough Files";
string sDirectoryName;
if (args.Length == 0)
{
sDirectoryName = Directory.GetCurrentDirectory();
}
else
{
sDirectoryName = args[0];
}
FileInfo[] files = GetFileList(sDirectoryName);
using (StreamWriter sw = new StreamWriter(@"Relative File Paths.txt"))
{
sw.WriteLine("// Program created by: Poab9200");
foreach (FileInfo file in files)
{
if (file.Extension == ".txt")
{
sw.WriteLine(file);
}
else { }
}
}
}
public static FileInfo[] GetFileList(string sDirectoryName)
{
FileInfo[] files = new FileInfo[0];
try
{
DirectoryInfo di = new DirectoryInfo(sDirectoryName);
files = di.GetFiles();
}
catch (Exception e)
{
Console.WriteLine("Directory \" + sDirectoryName" + "\" invalid");
Console.WriteLine(e.Message);
}
return files;
}
}
}