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

How to simultaneously create a new folder and multiple files in VSCode?

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

例如

1:右击select'New File'。

2:输入所需的文件夹和文件名。

3:第 1 步和第 2 步的结果。

有人知道是否可以使用类似的模式创建包含多个文件的文件夹吗?这就是我希望能够做到的。

我不认为你可以按照你展示的方式来做,但是通过任务来做是很容易的。在你的 tasks.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 来创建文件夹和文件,如果您使用的是 shell 而没有这些命令,请将您的命令换掉有。]