Folder Names Based on Filenames

前端 未结 1 644
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 09:21

This isnt really a coding question. I need to put all my files into individual directories so each file has its own directory with the name based on the filename. So before

1条回答
  •  借酒劲吻你
    2021-01-07 09:38

    No need to build an application. This simple one liner run from the Windows command line will move each file in a directory into a sub-directory based on the root name of the file.

    for %f in (*) do @(md "%~nf"&move "%f" "%~nf")>nul 2>&1
    

    Two files with the same base name but different extensions will be moved into the same directory. For example, "test.txt" and "text.doc" will both be moved into a directory named "test"

    Any file without an extension will not be moved.

    If you want to run this from a batch file, then

    @echo off
    for %%f in (*) do (
      md "%%~nf"
      move "%%f" "%%~nf"
    ) >nul 2>&1
    

    You requirements were not very clear. If your requirements differ, then the script can probably be modified fairly easily to suit your needs.

    0 讨论(0)
提交回复
热议问题