Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在目录中创建index.php文件_C#_File_Directory_Command Line Arguments - Fatal编程技术网

C# 在目录中创建index.php文件

C# 在目录中创建index.php文件,c#,file,directory,command-line-arguments,C#,File,Directory,Command Line Arguments,我想编写一个程序添加到右键菜单,当我从右键菜单运行程序时,在当前目录中创建一个index.php文件 Exmaple: 我进入C:\wamp\www 然后我右键单击某个地方,并希望选择createindex.php 这将在我单击的目录中创建一个名为index.php的新文件 所需操作: 一个名为index.php的新文件将在C:\wamp\www\index.php 更多详细信息: 我想让它看起来像“新建”中的“文本文档”: 右键单击=>new=>文本文档 当我们点击它时,windows会创

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

Exmaple:

  • 我进入
    C:\wamp\www

  • 然后我右键单击某个地方,并希望选择
    createindex.php

  • 这将在我单击的目录中创建一个名为
    index.php
    的新文件

所需操作:

一个名为
index.php
的新文件将在
C:\wamp\www\index.php

更多详细信息:

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

右键单击=>new=>文本文档

当我们点击它时,windows会创建“newtext Document.txt”。。。现在我想当我们点击我的程序窗口创建“index.php”文件

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

HKEY\u CLASSES\u 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
请参阅以下链接以了解相关信息:


您尝试过什么吗?我不知道如何在不同的时间获取当前目录路径。。。首先,我们将获得路径,以便创建文件!你可以将“获取当前目录路径”复制粘贴到谷歌上,并获得大量评论的答案。你试过/研究过什么?你的问题太宽泛了。不。。。你没有正确理解我的问题!当我使用Directory.GetCurrentDirectory()时;返回c:\users\username\documents\visualstudio 2012\Projects\Index.php\Index.php\bin\Debug!但我不想要它!我想要用户点击“createindex.php”选项的路径。。。例如在F:/New文件夹中的用户/单击“createindex.php”,然后程序将createindex.php放入F:/New文件夹/i在控制台应用程序项目上复制此代码。。。所以从注册表链接到右键菜单上的一个选项。。。但是,当我运行它时,cmd显示以下错误消息:“创建“index.php”时出错”:索引超出了数组的界限。“怎么办?您是否查看了
超级用户链接并遵循了所有说明?请查看我的问题。。。我现在已经编辑好了!有人在这里回答我吗?@R3Z4BH这将不起作用(如果没有非常深入的操作系统破解和重写),因为资源管理器实际上并不收集项目,它们保存在可执行文件中。另一个问题是,当打开右键单击菜单子项“新建”时,资源管理器会覆盖注册表中的所有项。。。如果我的答案对你有帮助,请将其标记为已解决!!