.bat文件的文件整理到文件夹中 [英] .bat file sorting files into folders

查看:281
本文介绍了.bat文件的文件整理到文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的图片集我想有自动按照日期排序放入文件夹,文件夹中的所有照片。幸运的是,文件的时间戳后已命名的:

For my picture collection I want to have all pictures in a folder automatically sorted into folders by date. Luckily the files are already named after the timestamp:


  • 2012-07-15 12.21.06.jpg

  • 2012-07-15 12.21.26.jpg

  • 2012-07-16 17.12.50.jpg

在这个例子中,两个第一文件应该夹2012-07-15,第三个在2012-07-16中结束。我试过和一派,所有我能找到是这样的:

In this example the two first files should end up in a folder 2012-07-15, the third one in 2012-07-16. I've tried and googled, all I can find is this:

for %%a in (*.jpg) do (
    md "%%~na" 2>nul
    move "%%a" "%%~na"
)

不过,让每个文件名的文件夹。我想有一个具有十个第一字符的变量,但得到完全糊涂和沮丧与变量的声明和使用DOS。谁能帮助?

But that makes a folder for every file name. I thought of having a variable that has the ten first chars, but get totally confused and frustrated with variable declaration and use in dos. Can anyone help?

推荐答案

下面是另外一个可能性,你怎么可以这样使用延迟扩展和子:

Here's another possibility how you could do this using delayed expansion and substrings:

SETLOCAL ENABLEDELAYEDEXPANSION
for %%a in (*.jpg) do (
    set f=%%a
    set g=!f:~0,10!
    md "!g!" 2>nul
    move "%%a" "!g!"
)

第一行开启的语法使用而不是的并具有跨preT效果的变量的值不作为块的第一行被执行(标准分批行为),但只有当执行线本身

The first line enables the syntax using ! instead of % and has the effect to interpret the value of the variable not as the first line of the block is executed (standard batch behavior), but only when the line itself is executed.

F:〜0,10 是语法来获得子 - 你以后总是10个字符长的日期

!f:~0,10! is the syntax to obtain a substring - the dates you're after are always 10 characters long.

这篇关于.bat文件的文件整理到文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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