2015-04-12 110 views

回答

3

您可以使用for循環,子和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返回當前目錄下的所有文件夾除外。子串符號是!variable:~start,length!

What is the best way to do a substring in a batch file?

+0

謝謝你,該訣竅 –

0

一襯爲命令提示符:

for %a in (*.jpg) do @set "FName=%~a"&call xcopy "%FName%" "%FName:~0,4%\%FName:~4,2%\"&&del "%~a"&set "FName=" 
相關問題