批量根据文件名创建文件夹,并将多个相关文件移动到创建的文件夹 [英] Batch Create a Folder Based on Filename, and Move Multiple Related Files to The Created Folder

查看:308
本文介绍了批量根据文件名创建文件夹,并将多个相关文件移动到创建的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多年来,我一直把我所有的电影一起放到一个文件夹,以及所有的额外。
我已经意识到现在经过几个挫折保持nfo和艺术的备份将节省我的生命,并保持数据库更多的可用性,当添加一个新的Kodi设置(电视,平板电脑,笔记本电脑等...) 。
所以我试图批量创建一个文件夹基于电影的文件名,并移动多个相关文件到创建的文件夹。



要清楚,我想要一个电影的文件夹名称,并有所有相关的文件进入该文件夹。电影文件名的格式可以改变,因为他们不都有相同的信息,即Director的剪辑,unedit,最终版本,它们在brakets []。主电影名称在所有情况下都将是最小的文件名,我不想要的文件夹中包含文件名中包含[Extra]的文件命名。
一般来说,格式为非电影视频的电影(年)[额外信息] ... [额外信息]小描述。



我想出的最好的是:

  for %% i in(*)do md%%〜ni &&移动%%〜i%%〜ni

为每个文件创建一个文件夹,并将所有文件移动到相应的文件夹,但相关内容现在位于不同的文件夹中,并且完全相同的文件名在主文件夹中。



我想要完成的范例:




  • \'71 [Extra] sup stuff.mp4

  • \'71.mkv

  • \3 Geezers! (2013)-fanart.jpg

  • \3 Geezers! (2013)-poster.jpg

  • \3 Geezers! (2013).mp4

  • \3 Geezers! (2013).nfo

  • \3 Women(1977)-fanart.jpg

  • \3 Women(1977)-poster.jpg

  • \3 Women(1977).mp4

  • \3 Women(1977).nfo

  • \12 Years A Slave(2013).mp4

  • \13(2010).mp4

  • \A Case Of You(2013) .avi

  • \A Single Shot(2013).mp4

  • \Abre Los Ojos(1997)[Open Your Eyes] [Extra] Test.mp4

  • \Abre Los Ojos(1997)[Open Your Eyes] [SPA] .avi

  • \Abre Los Ojos(1997)[打开你的眼睛] [SPA] .srt

  • \GBF (2013).mp4

  • \G.I。 Joe Retaliation(2013).mkv

  • \G.I。 Joe报复(2013).srt

  • \Test Movie(1977)[Comm] .mp4



收件人:




  • \'71 \'71 [Extra] sup stuff.mp4

  • \'71\'71.mkv

  • \3 Geezers! (2013)\3 Geezers! (2013)-fanart.jpg

  • \3 Geezers! (2013)\3 Geezers! (2013)-poster.jpg

  • \3 Geezers! (2013)\3 Geezers! (2013).mp4

  • \3 Geezers! (2013)\3 Geezers! (2013).nfo

  • \3女性(1977)\3女性(1977)-fanart.jpg

  • \3女性1977)\3 Women(1977)-poster.jpg

  • \3 Women(1977)\3 Women(1977).mp4

  • \3 Women(1977)\3 Women(1977).nfo

  • \12一年奴隶(2013)\12一年奴隶(2013).mp4

  • \13(2010)\13(2010).mp4

  • \A Case Of You(2013)\A Case Of You 2013).avi

  • \A Single Shot(2013)\A Single Shot(2013).mp4

  • \Abre Los Ojos 1997)[Open Your Eyes] [SPA] \Abre Los Ojos(1997)[Open Your Eyes] [SPA] [Extra] Test.mp4

  • \Abre Los Ojos )[打开你的眼睛] [SPA] \Abre Los Ojos(1997)[打开你的眼睛] [SPA] .avi

  • \Abre Los Ojos(1997) ] [SPA] \Abre Los Ojos(1997)[张开你的眼睛] [SPA] .srt

  • \GBF (2013)\G.B.F。 (2013).mp4

  • \G.I。 Joe报复(2013)\G.I。 Joe Retaliation(2013).mkv

  • \G.I。 Joe报复(2013)\G.I。 Joe Retaliation(2013).srt

  • \Test Movie(1977)[Comm] \Test Movie(1977)[Comm] .mp4



    • 任何人都可以帮助我这个批处理代码?并不是所有的文件名都是Movie(Year)[Comm] ...,有些只是Movie,或者是电影[Comm]。



      总结:基于电影的文件夹,即具有特定视频扩展名的任何文件,例如mp4,mkv,avi等...也不包含:[Extra];然后将所有相关文件移动到该文件夹​​中。



      我浏览过这些来源:


      1. 根据文件名的一部分批量创建文件夹并将文件移动到该文件夹​​中

      2. 批量创建的文件夹由文件名部分和移动

      3. 根据一系列文件批量创建文件夹并移动到子目录

      4. 基于文件名创建文件夹的批处理脚本

      5. 根据文件名创建文件夹并将这些文件移动到该文件夹​​中

      6. http://superuser.com/questions/762113/cmd-command- to-create-folder-for-each-file-and-move-file-into-folder

      7. 批处理脚本将一个文件夹中的每个文件移动到文件?

      8. Batch命令将png文件移动到文件夹同名文件和文件夹

      9. 批量命令检查部分文件名,然后移动

      10. AZ索引Windows CMD命令行: http://ss64.com/nt/


      解决方案

      虽然您的描述很充分,但您忘记了一些具体的细节;例如:使用Movie(year)部分启动所有文件名?如果是这样,则此批处理文件会执行您想要的操作:



      EDIT :Ops,此版本可以正常工作:

        @echo off 
      setlocal

      setbasename = 。
      for / Ftokens = 1 * delims =。 %% a in('dir / B / AD ^ | sort / R')do(
      setfilename = %% a
      setlocal EnableDelayedExpansion
      for / Fdelims = %c in(!basename!)do if!filename:%% c =!equ!filename!(
      setbasename =!filename!
      md!

      move!filename!。%% b!basename!
      for / Fdelims =%% c in(!basename! b $ b endlocal
      setbasename = %% c



      For years I've always had all my movies dumped into one folder, along with all of their extras. I've realized now after several frustrations keeping a backup of nfo and art would save me hours of life, and keep the database more usable when adding a new Kodi setup (TV, Tablet, Laptop, etc...). So I'm trying to batch create a folder based on the filename of the movie, and move multiple related files to the created folder.

      To be clear, I want to make a folder name of the movie and have all the related files go into that folder. The movie filesnames' format can change because they don't all have the same info, i.e. Director's cut, unedit, ultimate edition, which are in brakets []. The main movie name would in all cases be the smallest filename, and I'd never want the folder to be named with a file that contained "[Extra]" in the filename. Generally speaking the format is "Movie (year) [extra info] ... [extra info] small description here" for the non-movie videos.

      The best I've come up with is:

      for %%i in (*) do md "%%~ni" && move "%%~i" "%%~ni"
      

      The problem right now is I'm creating a folder for every file and moving all the files to the respective folders but related content is now in different folders and things with the exact same filename is getting left in the main folder.

      An example of what I'm trying to accomplish:

      • \'71 [Extra] sup stuff.mp4
      • \'71.mkv
      • \3 Geezers! (2013)-fanart.jpg
      • \3 Geezers! (2013)-poster.jpg
      • \3 Geezers! (2013).mp4
      • \3 Geezers! (2013).nfo
      • \3 Women (1977)-fanart.jpg
      • \3 Women (1977)-poster.jpg
      • \3 Women (1977).mp4
      • \3 Women (1977).nfo
      • \12 Years A Slave (2013).mp4
      • \13 (2010).mp4
      • \A Case Of You (2013).avi
      • \A Single Shot (2013).mp4
      • \Abre Los Ojos (1997) [Open Your Eyes] [SPA] [Extra] Test.mp4
      • \Abre Los Ojos (1997) [Open Your Eyes] [SPA].avi
      • \Abre Los Ojos (1997) [Open Your Eyes] [SPA].srt
      • \G.B.F. (2013).mp4
      • \G.I. Joe Retaliation (2013).mkv
      • \G.I. Joe Retaliation (2013).srt
      • \Test Movie (1977) [Comm].mp4

      To:

      • \'71\'71 [Extra] sup stuff.mp4
      • \'71\'71.mkv
      • \3 Geezers! (2013)\3 Geezers! (2013)-fanart.jpg
      • \3 Geezers! (2013)\3 Geezers! (2013)-poster.jpg
      • \3 Geezers! (2013)\3 Geezers! (2013).mp4
      • \3 Geezers! (2013)\3 Geezers! (2013).nfo
      • \3 Women (1977)\3 Women (1977)-fanart.jpg
      • \3 Women (1977)\3 Women (1977)-poster.jpg
      • \3 Women (1977)\3 Women (1977).mp4
      • \3 Women (1977)\3 Women (1977).nfo
      • \12 Years A Slave (2013)\12 Years A Slave (2013).mp4
      • \13 (2010)\13 (2010).mp4
      • \A Case Of You (2013)\A Case Of You (2013).avi
      • \A Single Shot (2013)\A Single Shot (2013).mp4
      • \Abre Los Ojos (1997) [Open Your Eyes] [SPA]\Abre Los Ojos (1997) [Open Your Eyes] [SPA] [Extra] Test.mp4
      • \Abre Los Ojos (1997) [Open Your Eyes] [SPA]\Abre Los Ojos (1997) [Open Your Eyes] [SPA].avi
      • \Abre Los Ojos (1997) [Open Your Eyes] [SPA]\Abre Los Ojos (1997) [Open Your Eyes] [SPA].srt
      • \G.B.F. (2013)\G.B.F. (2013).mp4
      • \G.I. Joe Retaliation (2013)\G.I. Joe Retaliation (2013).mkv
      • \G.I. Joe Retaliation (2013)\G.I. Joe Retaliation (2013).srt
      • \Test Movie (1977) [Comm]\Test Movie (1977) [Comm].mp4

      Can anyone help me with this batch code? Not all the files names are Movie (Year) [Comm] ..., some are just Movie, or Movie [Comm].

      In summary: I want to create a folder based on a movie, ie any file with a specific video extension, such as mp4, mkv, avi, etc... that also doesn't contain: [Extra]; then move all associated files into that folder.

      I've gone through these sources:

      1. Batch create folders based on part of file name and move files into that folder
      2. Batch Created Folder By Filename Part and Move
      3. Batch create folders based on series of files and move to subdirectory
      4. Batch script to create folders based on filenames
      5. create folders based on a file name and move those files into that folder
      6. http://superuser.com/questions/762113/cmd-command-to-create-folder-for-each-file-and-move-file-into-folder
      7. Batch script that moves each file in a folder into their own folders named after the file?
      8. Batch command move png files to folders same name files and folders
      9. Batch command to check for partial filename then move
      10. An A-Z Index of the Windows CMD command line: http://ss64.com/nt/

      解决方案

      Although your description is ample, you forgot to give some specific details; for example: starts all file names with the "Movie (year)" part? If so, then this Batch file do what you want:

      EDIT: Ops, I misread the requirements! This version works correctly:

      @echo off
      setlocal
      
      set "basename=."
      for /F "tokens=1* delims=." %%a in ('dir /B /A-D ^| sort /R') do (
         set "filename=%%a"
         setlocal EnableDelayedExpansion
         for /F "delims=" %%c in ("!basename!") do if "!filename:%%c=!" equ "!filename!" (
            set "basename=!filename!"
            md "!basename!"
         )
         move "!filename!.%%b" "!basename!"
         for /F "delims=" %%c in ("!basename!") do (
            endlocal
            set "basename=%%c
         )
      )
      

      这篇关于批量根据文件名创建文件夹,并将多个相关文件移动到创建的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆