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;
        }
    }
}

Recommended Answers

All 4 Replies

".lnk" file) and we all know what this file does(points to the file of which was linked)

???
I know a linker is a part of some compilers.
Do you mean command line arguments?
You seem to know that, so what is your problem?

???
I know a linker is a part of some compilers.
Do you mean command line arguments?
You seem to know that, so what is your problem?

Shortcuts use the extension .lnk. If you have shortcuts look at them via(Right click > Properties then click the general tab and it should show the name of the extension...

Ok, I did a little research and yes that is what I am looking for. But I want to have my program accept the command line arguments. How would I go about doing this?

Ok never mind I figured out a way to make it work and here is where I got the info to figure it out.

Access Command Line

That info helped out a lot. Anyways thanks for your help. You saying Command Line Arguments was the phrase I needed to find the info.

Thanks -Poab9200

Glad I could sort this out!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.