当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.WriteAllLines方法代码示例

本文整理汇总了C#中FileInfo.WriteAllLines方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.WriteAllLines方法的具体用法?C# FileInfo.WriteAllLines怎么用?C# FileInfo.WriteAllLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileInfo的用法示例。


在下文中一共展示了FileInfo.WriteAllLines方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    public static void Main(String[] args)
    {
        var sublime = @"C:\Program Files\Sublime Text 2\sublime_text.exe";
        var home = new DirectoryInfo(@"%APPDATA%\Sublime Text 2".Expand());

        var projects = new DirectoryInfo(home.FullName + @"\Projects");
        var default_prj = null as String;
        if (projects.Exists && projects.GetFiles("*.is.default").Length == 1) {
          var default_file = projects.GetFiles("*.is.default")[0];
          default_prj = Path.GetFileNameWithoutExtension(default_file.FullName);
          default_prj = Path.GetFileNameWithoutExtension(default_prj);
          if (args.Length == 0) args = new []{default_prj};
        }

        if (args.Length > 0) {
          if (args[0] == "/new") {
        args = args.Skip(1).ToArray();

        var file0 = new FileInfo(args[0]);
        var dir0 = new DirectoryInfo(args[0]);
        if (file0.Exists) dir0 = file0.Directory;

        FileInfo project = null;
        if (args.Length > 2 && args[args.Length - 2] == "/name") {
          project = new FileInfo(projects + "\\" + args[args.Length - 1] + ".sublime-project");
          if (project.Exists) {
            MessageBox.Show(String.Format("Project \"{0}\" already exists found. \r\n\r\n" +
                                          "There already exists find project file {1}.", args[args.Length - 1], project.FullName),
                                          "Sublime Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
          }
          args = args.Take(args.Length - 2).ToArray();
        } else {
          var idx = 0;
          Func<FileInfo> gen = () => new FileInfo(projects + "\\" + dir0.Name + (idx == 0 ? "" : idx.ToString()) + ".sublime-project");
          while (gen().Exists) idx++;
          project = gen();
        }

        var lines = new List<String>();
        lines.Add("{");
        lines.Add("  \"folders\":");
        lines.Add("  [");
        for (var i = 0; i < args.Length; ++i) {
          var file = new FileInfo(args[i]);
          var dir = new DirectoryInfo(args[i]);
          if (file.Exists) dir = file.Directory;

          var dir_as_sublimepath = dir.FullName;
          dir_as_sublimepath = dir_as_sublimepath.Replace("\\", "/");
          dir_as_sublimepath = dir_as_sublimepath.Replace(":/", "/");
          dir_as_sublimepath = "/" + dir_as_sublimepath;

          lines.Add("    {");
          lines.Add("      \"path\": \"" + dir_as_sublimepath + "\"");
          lines.Add("    }");
          if (i != args.Length - 1) lines[lines.Count - 1] = lines[lines.Count - 1] + ",";
        }
        lines.Add("  ]");
        lines.Add("}");
        project.WriteAllLines(lines);

        lines = new List<String>();
        lines.Add("{");
        lines.Add("  \"build_system\": \"Packages/User/Myke.sublime-build\",");
        lines.Add("  \"show_minimap\": false,");
        lines.Add("  \"show_open_files\": true,");
        lines.Add("  \"show_tabs\": true,");
        lines.Add("  \"side_bar_visible\": true,");
        lines.Add("  \"side_bar_width\": 256.0,");
        lines.Add("  \"status_bar_visible\": true");
        lines.Add("}");
        var workspace = new FileInfo(Path.ChangeExtension(project.FullName, "sublime-workspace"));
        workspace.WriteAllLines(lines);

        args = new []{"--project", "\"" + project.FullName + "\""}.Concat(args).ToArray();
          } else {
        var file0 = new FileInfo(args[0]);
        var dir0 = new DirectoryInfo(args[0]);
        if (file0.Exists) dir0 = file0.Directory;

        if (file0.Exists || dir0.Exists || args[0].Contains(".")) {
          // don't do any postprocessing of args => open in current instance of sublime
          // upd. the hack below is needed because "sublime file_name" is currently broken!!
          var sublimeNotYetOpen = Process.GetProcesses().Where(process => process.ProcessName != null && process.ProcessName.EndsWith("sublime_text")).Count() == 0;
          if (sublimeNotYetOpen) {
            var project = new FileInfo(projects + "\\kep.sublime-project");
            args = new []{"--project", "\"" + project.FullName + "\"", args[0]};
          }
        } else {
          var project = new FileInfo(projects + "\\" + args[0] + ".sublime-project");
          if (!project.Exists) {
            MessageBox.Show(String.Format("Project \"{0}\" not found. \r\n\r\n" +
                                          "Could not find project file {1}.", args[0], project),
                                          "Sublime Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
          } else {
            if (args.Length == 2 && (args[1].ToLower() == "/reg" || args[1].ToLower() == "/register")) {
              projects.GetFiles("*.is.default").ToList().ForEach(file => file.Delete());
              var default_file = new FileInfo(Path.ChangeExtension(project.FullName, "is.default"));
//.........这里部分代码省略.........
开发者ID:xeno-by,项目名称:dotwindows,代码行数:101,代码来源:sublime.cs


注:本文中的FileInfo.WriteAllLines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。