在目录中创建 index.php 文件

Create index.php file in directory

我想写一个程序添加到右键菜单中,当我运行程序从右键菜单中创建一个index.php文件在当前目录下!

示例:

所需操作:

将在 C:\wamp\www\index.php

创建一个名为 index.php 的新文件

更多详情:

我想让它看起来像 "New" 中的 "Text Document":

right-click => new => text document

当我们点击它时 windows 创建 "New Text Document.txt" ...现在我想要当我们点击我的程序时 windows 创建 "index.php" 文件!

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

HKEY_CLASSES_ROOT\Directory\Background\shell\

感谢所有...

看看这个:

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

请查看以下链接: