批量创建的文件夹通过文件名部分和移动 [英] Batch Created Folder By Filename Part and Move

查看:417
本文介绍了批量创建的文件夹通过文件名部分和移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现脱线的帖子,并已与它玩了。我似乎无法得到DIR部分解析出文件名创建文件夹和文件移动到相应文件夹中。

I found magoo's post and been playing around with it. I can't seem to get the DIR part to parse out the file name to create the folder and move the files to the respective folders. The following are examples of the files I'm working with:

...
800.1.gif
800.2.gif
800.3.jpg
801.1.gif
801.2.jpg
801.3.gif
...

批应创建文件夹800和801分别移动800.X和801.X文件。我试过FINDSTR和其他口罩和运气不好。

The batch should create folders 800 and 801 and move the 800.X and 801.X files respectively. I've tried FINDSTR and other masks and not having much luck.

下面是脱线的原批code(来源: http://bit.ly/1ua8IIF ):

Here's magoo's original batch code (source: http://bit.ly/1ua8IIF):

@ECHO OFF
SETLOCAL
SET "sourcedir=c:\sourcedir"
PUSHD %sourcedir%
FOR /f "tokens=1*" %%a IN (
 'dir /b /a-d "*_*_*-*-* *.*"'
 ) DO (  
 ECHO MD %%a
 ECHO MOVE "%%a %%b" .\%%a\
)
POPD
GOTO :EOF

在几个小时后我尝试:

My attempt after a few hours:

@ECHO OFF
SETLOCAL
SET "sourcedir=c:\sourcedir"
PUSHD %sourcedir%
FOR /f "tokens=1*" %%a IN (
 'dir /b /a-d ^|findstr /r "\.[1-9]"'
 ) DO (  
 ECHO MD %%a
 ECHO MOVE "%%a %%b" .\%%a\
)
POPD
GOTO :EOF

我仍然玩弄它,但任何帮助将大大AP preciated呢!

I'm still playing around with it but any help would be greatly appreciated it!

推荐答案

的修改你需要做的:

FOR /f "tokens=1*delims=." %%a IN (

添加 delims = 表示请客作为分隔符。在原来,<大骨节病>空间使用默认的分隔符。

Adding the delims=. means "treat . as a delimiter." In the original, the default delimiter Space was used.

 'dir /b /a-d "*.*.gif" "*.*.jpg"'

执行匹配的文件目录列表 *。*。GIF *。*。JPG

引号是不必要的,但无害的。在原来,有空间所需要的文件掩码列入面具串;空间是一个分隔符,引用字符串中删除的特殊含义。

The quotes are unnecessary but harmless. In the original, the filemask needed to have the space included in the mask string; space is a separator and quoting the string removes the special meaning.

这将匹配任何匹配扩展名的文件。如果你想匹配的模式中的任何文件 *。*。* 然后随意改变这

This would match any file matching either extension. If you want to match any file of the pattern *.*.* then feel free to change this to

 'dir /b /a-d *.*.*'

最后,

 ECHO MOVE "%%a.%%b" .\%%a\

它只是重新插入重建原始字符串的问题在 为解析出由 - 在这种情况下,但在原来的<大骨节病>空间

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

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