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
请参阅以下链接以了解相关信息:
超级用户链接并遵循了所有说明?请查看我的问题。。。我现在已经编辑好了!有人在这里回答我吗?@R3Z4BH这将不起作用(如果没有非常深入的操作系统破解和重写),因为资源管理器实际上并不收集项目,它们保存在可执行文件中。另一个问题是,当打开右键单击菜单子项“新建”时,资源管理器会覆盖注册表中的所有项。。。如果我的答案对你有帮助,请将其标记为已解决!!