使用bat将文件移动到基​​于部分名称的文件夹

时间:2016-05-12 00:52:58

标签: file batch-file directory

我在文件夹上有很多文件,我想将它们移动到与其名称一致的文件夹中。

示例:

[PartOfItsName] Season01Episode02 (04.04.16).mp4
[PartOfAnotherName] Season02Episode02 (05.02.16).mp4
[AndAnotherOne] Season03Episode04 (02.01.16).mp4

After moved I want something like this:

C:/[PartOfItsName]/[PartOfItsName] Season01Episode02 (04.04.16).mp4
C:/[PartOfAnotherName]/[PartOfAnotherName] Season02Episode02 (05.02.16).mp4
C:/[AndAnotherOne]/[AndAnotherOne] Season03Episode04 (02.01.16).mp4

不会修改文件的名称,只需要创建括号中名称的文件夹,然后将文件移动到各自的文件夹中。

2 个答案:

答案 0 :(得分:1)

在PowerShell中,您可以使用:

dir *.mp4 | mv -Dest { [regex]::Match($_, '\[.*\]').Value }

这可能在批处理文件中起作用:

dir /b *.mp4 > tmp
for /f "tokens=1,2 delims=]" %%f in (tmp) do (
    mkdir "%%f]"
    move "%%f]%%g" "%%f]"
)
del tmp

NB。对于这两个版本,每个.mp4文件必须有一个[..]部分,并且名称中的任何其他位置都没有方括号。

答案 1 :(得分:1)

即使在开始import React from 'react'; import {Tab, Tabs} from '../../../../../components/Tabs'; import {TitleBar} from '../../../../../components/TitleBar'; import List from './List.jsx' import ListItem from './ListItem.jsx' class MsgCenter extends React.Component { constructor() { super() this.checkItemsHasUnviewed = this.checkItemsHasUnviewed.bind(this) this.state = { bulletinHasNew: false, newsesHasNew: false, active: true } } checkItemsHasUnviewed(items) { let hasUnViewed = false if (items && items.length > 0) { for (let i = 0; i < items.length; i++) { if (!items[i].viewed) { hasUnViewed = true break } } } return hasUnViewed } render() { let bulletinHasUnviewed = this.checkItemsHasUnviewed(this.props.bulletins.items) let newsHasUnviewed = this.checkItemsHasUnviewed(this.props.newses.items) return ( <div> <TitleBar title="Message Center"></TitleBar> <Tabs showInkBar> <Tab label="Bulletin" value={0} badge={bulletinHasUnviewed ? <span className="circleBadge"></span> : null }> <List> { this.props.bulletins.items.map(function (item) { return ( <ListItem item={item} key={'bulletin.' + item.id}></ListItem> ) }) } </List> </Tab> <Tab label="News" value={1} badge={newsHasUnviewed ? <span className="circleBadge"></span> : null }> <List> { this.props.newses.items.map(function (item) { return ( <ListItem item={item} key={'news' + item.id}></ListItem> ) }) } </List> </Tab> </Tabs> </div> ) } } MsgCenter.defaultProps = { activeSubject: 'bulletins', bulletins: { isFetching: false, isRefreshing: false, page: 1, totalPage: 1, items: [ { id: 1, title: 'This is bulletin 1', publicDate: 1461513600000, viewed: true }, { id: 2, title: 'This is bulletin 2', publicDate: 1461427200000, viewed: true }, { id: 3, title: 'This is bulletin 3', publicDate: 1461340800000, viewed: true }, { id: 4, title: 'This is bulletin 4', publicDate: 1461254400000, viewed: false } ] }, newses: { isFetching: false, isRefreshing: false, page: 1, totalPage: 1, items: [ { id: 5, title: 'This is news 1', publicDate: 1458748800000, viewed: false }, { id: 6, title: 'This is news 2', publicDate: 1458662400000, viewed: false }, { id: 7, title: 'This is news 3', publicDate: 1458576000000, viewed: true }, { id: 8, title: 'This is news 4', publicDate: 1458489600000, viewed: true }, ] } } module.exports = MsgCenter 之前还有其他字符,此批处理脚本也能正常工作。

[

在命令行上可以很容易地完成它作为一个很长的单行程序:

@echo off
for %%F in (*[*]*.mp4) do for /f "delims=[] eol=[ tokens=2" %%A in ("x%%F") do (
  md "c:\[%%A]" 2>nul
  move "%%F" "c:\[%%A]" >nul
)