查找文件并分组到目录中

查找文件并分组到目录中

我有一个文件夹和子文件夹以及大量文件,如下所示:

Folder  called Movies
Sub Folder called "009 - A bad Wolf"
Files called  " 009  A bad Wolf.avi"
Files  called  " 009  A bad Wolf.txt"
Files  called  " 009 - A bad Wold.nfo"
Sub folder   A damn Good Film
Files          >  A Very good Film .mp4
Files          >  A very good Film .nfo
Files          > A Very good Film.txt
Files          > American Babe -Estelle Feat Kan Wass.mkv
Files          > American Babe -Estelle Feat Kan Wass.nfo
Files          > American Babe -Estelle Feat Kan Wass-poster.jpg
Files          > American.History.X.1998.Bluray.1080p.DTS-HD-7.1.x264-Grym
Sub Folder     > Baste - taste
.
.
Files          > Baa Baa Sheep.ogg
Files          > Baa Baa Sheep.nfo
Files          > Baa Baa Sheep.txt
.
.
Files          > Saa Baa Sheep.mp3
Files          > Saa Baa Sheep.nfo
.
Files          > Zaa Baa Sheep.flv
Files          > Zaa Baa Sheep-poster.jpg
Files          > Zaa Baa Sheep.nfo
Files          > Zaa Baa Sheep.txt

我怎样才能将每组相似的文件放入单独的目录中,而无需逐一检查?子文件夹中有 1075 个文件和子文件夹,主文件夹 + 子文件夹中有 6 个文件,我完全不知所措。我知道我必须使用 find 和 exec,但如何创建具有匹配名称的目录?即应该是这样的:

Folder > Movies
Sub Folder > 009 - A bad Wolf with the following files in this sub folder:        
        Files          >  009 - A bad Wolf.avi
        Files          >  009 - A bad Wolf.txt
        Files          >  009 - A bad Wold.nfo
 Sub folder     >  A damn Good Film with all the files of same name in this sub folder
 Sub Folder     > A Very good Film with all these files in this sub folder :            Files          >  A Very good Film .mp4
         Files          >  A very good Film .nfo
         Files          > A Very good Film.txt
Sub Folder     > American Babe -Estelle Feat Kan Wass with all these files of same name in this sub folder:
         Files          > American Babe -Estelle Feat Kan Wass.mkv
         Files          > American Babe -Estelle Feat Kan Wass.nfo
         Files          > American Babe -Estelle Feat Kan Wass-poster.jpg
Sub Folder     > American.History.X.1998.Bluray.1080p.DTS-HD with files of same name in this  sub folder:
          Files         > American.History.X.1998.Bluray.1080p.DTS-HD-7.1.x264-Grym
Sub Folder     > Baste - taste as above with files of same names in this sub folder
.
.
Sub Folder     > Baa Baa Sheep with files of same name in this sub folder:
       Files          > Baa Baa Sheep.ogg
       Files          > Baa Baa Sheep.nfo
       Files          > Baa Baa Sheep.txt
.
Sub Folder     > Saa Baa Sheep with files of same name in this sub folder:
       Files          > Saa Baa Sheep.mp3
       Files          > Saa Baa Sheep.nfo
.
Sub Folder     > Zaa Baa Sheep with files of same name in this sub folder:
       Files          > Zaa Baa Sheep.flv
       Files          > Zaa Baa Sheep-poster.jpg
       Files          > Zaa Baa Sheep.nfo
       Files          > Zaa Baa Sheep.txt

答案1

完成这个任务非常容易,我一直使用这种方法。

导航到相关目录。按 SHIFT + 右键单击​​(在文件夹的空白部分)。选择“在此处打开命令窗口”。终端会话将在此目录中打开。

当您位于此目录中时,您可以使用 Windows、新文件夹等创建所需的子文件夹。或者您可以使用以下命令:

创建目录(创建文件夹)
>mkdir foldername
将所有文件扩展名移动到新子文件夹(例如所有 flv 文件)
>mv *.flv ./foldername

如果您希望移动具有相似标题的文件,请使用以下命令:*(星号)是通配符。引号使字符串保持完整,保留空格;否则将跳过空格。

>mkdir "咩黑羊"
>mv "咩黑"*.* ./"咩黑羊"

上面:
mv = 移动
“baa black”* = 以“baa black” + *(之后的任何字符串)开头
。/ = 此目录
。/foldername = 此目录中名为 foldername 的文件夹

mv "baa black"*.* ./"baa black sheep" = 移动所有以字符串 'ball black' 开头的文件并将其移动到目录 'baa black sheep'

在此处输入图片描述


在此处输入图片描述

如果您是第一次使用命令行界面,上面的图片应该可以帮助您理解这个概念。


仅供参考:最好保持文件名简短,不带空格,目录也一样。我建议你也查看一下“Windows DOS 命令”来学习一些技巧。

相关内容