如何批移动文件更新的文件名的文件夹? [英] how to batch move files date filename folder?

查看:130
本文介绍了如何批移动文件更新的文件名的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多命名为YYYYMMDD_HHmm.jpg图像文件

I have lots of image files named as YYYYMMDD_HHmm.jpg

我怎样才能将这些文件移动到:目标目录\\ YYYY \\ MM \\ YYYYMMDD_HHmm.jpg

How can I move these files to: target_directory\YYYY\MM\YYYYMMDD_HHmm.jpg ?

感谢您

推荐答案

您可以使用循环,子,和的mkdir

You can use a for loop, substrings, and mkdir:

@echo off
setlocal enabledelayedexpansion

for /f %%a in ('dir /b /a-d') do (
    set filename=%%a

    ::exclude this file
    if not "!filename!" == "%~nx0" (

        ::substr to grab characters 0-4 and 4-6 as year and month
        set year=!filename:~0,4!
        set month=!filename:~4,2!

        ::make dirs for the files if they don't already exist
        if not exist !year! mkdir !year!
        if not exist !year!\!month! mkdir !year!\!month!

        ::move the files there
        move !filename! !year!\!month!
    )
)

for循环运行 DIR / B / A-D 返回在当前目录中的所有文件夹除外。子串符号是变量:!!〜开始,长度

The for loop runs dir /b /a-d which returns all files in the current directory except folders. Substring notation is !variable:~start,length!.

<一个href=\"http://stackoverflow.com/questions/636381/what-is-the-best-way-to-do-a-substring-in-a-batch-file\">What是做一个字符串在批处理文件?最好的办法

这篇关于如何批移动文件更新的文件名的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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