【问题标题】:Use filename as variable when replacing text in files替换文件中的文本时使用文件名作为变量
【发布时间】:2014-07-22 14:51:46
【问题描述】:

在崇高文本中使用查找/替换文件时是否可以引用当前文件的名称?或者可能在其他文本编辑器中?

【问题讨论】:

  • 简短回答:不。哈克回答:可能如果你创建你的own plugin

标签: regex replace sublimetext3


【解决方案1】:

使用LINQPad 非常简单,只需选择“Language C# Statement(s)”,然后执行以下操作:

var files = new DirectoryInfo(@"C:\SomePath").GetFiles("*.*", SearchOption.AllDirectories);
foreach(var fileInfo in files)
{
    var text = File.ReadAllText(fileInfo.FullName);
    text = Regex.Replace(text, "pattern", fileInfo.Name); // Replace "pattern" with filename
    File.WriteAllText(fileInfo.FullName, text);
}

【讨论】:

  • 你拯救了我的一天! 550 个 html 文件在 3 秒内重命名...
猜你喜欢
  • 2018-09-01
  • 2017-12-03
  • 1970-01-01
  • 1970-01-01
  • 2018-01-08
  • 1970-01-01
  • 2014-10-01
  • 2014-09-22
  • 1970-01-01
相关资源
最近更新 更多