在目录[关闭]中创建index.php文件

问题描述 投票:0回答:1

我想编写一个程序添加到右键菜单中,当我从右键菜单运行该程序时,会在当前目录中创建一个

index.php
文件!

示例:

  • 我去

    C:\wamp\www

  • 然后我右键单击某处并想要选择

    create index.php

  • 这应该会在我单击的目录中创建一个名为

    index.php
    的新文件

期望的行动:

将在

index.php
 创建一个名为 
C:\wamp\www\index.php

的新文件

更多详情:

我想让它看起来像“新建”中的“文本文档”:

right-click => new => text document

当我们单击它时,窗口创建“新文本文档.txt”...现在我想当我们单击我的程序时,窗口创建“index.php”文件!

该程序将在其中运行的注册表路径:

HKEY_CLASSES_ROOT\Directory\Background\shell\

感谢大家...

c# file directory command-line-arguments
1个回答
0
投票

看看这个:

using System;
using System.IO;

namespace createIndex_php
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = string.Empty;
            try
            {
                if (File.Exists(args[0])) // right clicked on a file in explorer
                {
                    path = Path.GetDirectoryName(args[0]);
                }
                else
                {
                    path = args[0];
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format(@"Error while creating ""index.php"": {0}", ex.Message));
                Console.ReadKey();
            }

            if (path != string.Empty)
            {
                path = Path.Combine(path, "index.php");
                try
                {
                    File.Create(path);
                    Console.WriteLine(@"""index.php"" created!");
                    Console.ReadKey();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(string.Format(@"Error while creating ""index.php"": {0}", ex.Message));
                    Console.ReadKey();
                }
            }
        }
    }
}

这将创建

index.php
文件。

无论如何,您必须使用

regedit
将您的应用程序订阅到右键菜单,然后转到以下键:

HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers

请参阅以下链接:

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.