如何在VSCode中同时创建一个新文件夹和多个文件?

时间:2020-10-07 16:53:19

标签: visual-studio-code vscode-settings

我最近在Visual Studio Code中发现可以使用以下样式同时创建新文件夹和新文件:Test / Test.jsx

例如

1:右键单击并选择“新文件”。 New File

2:输入所需的文件夹和文件名。 Enter folder and file name

3:步骤1和2的结果。 Folder and file creation

有人知道是否可以使用类似的模式创建包含多个文件的文件夹?这就是我想要做的。 Add multiple files to a new folder

1 个答案:

答案 0 :(得分:0)

我认为您无法按照显示的方式进行操作,但是通过任务完成操作非常容易。在您的task.json中:

{
  "version": "2.0.0",

  "tasks": [
    {
      "label": "new react folder and files",

      "command": "mkdir ${input:dirName} && touch '${input:dirName}/${input:dirName}.component.jsx' '${input:dirName}/${input:dirName}.styles.jsx'",

      "type": "shell",
      "problemMatcher": [],
      "presentation": {
        "echo": false,
        "reveal": "silent",
        "focus": false,
        "panel": "shared",
        "showReuseMessage": false,
        "clear": true
      },
   }
],  

// ........................................................................................
  
  "inputs": [

    {
      "type": "promptString",
      "id": "dirName",
      "description": "Complete my folder name",
      "default": "jsx folder to create"
    }
  ]
}

以及一些用于触发任务的键绑定(在您的keybindings.json中):

[
  {
    "key": "alt+j",
    "command": "workbench.action.tasks.runTask",
    "args": "new react folder and files",
  }
]

这将提示您输入目录名称,然后在其中创建文件夹和两个文件。

[[如果您使用的外壳没有这些命令,则我会使用bash命令mkdirtouch创建文件夹和文件。]

create a react folder and files with a task

相关问题