批处理文件 - 日期变量和移动文件具有可变日期的文件名从一个文件夹到另一个 [英] Batch file - date variables and moving files with variable date file name from one folder to another

查看:284
本文介绍了批处理文件 - 日期变量和移动文件具有可变日期的文件名从一个文件夹到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助,请。我试图创建一个批处理文件从一个文件夹移动到另一个文件。该文件名具有可变YYYY-MM格式和其它的数据之前或之日起。批处理需要将文件移动到服务器目录具有相同MMMM-YY文件夹名。

I need some assistance, please. I'm trying to create a batch file to move files from one folder to another. The file name will have variable yyyy-mm format plus additional data before or after the date. The batch will need to move the file to a server directory with the same mmmm-yy folder name.

我拿出低于code,但它不是做得比较工作。

I've come up with the code below, but it doesn't quite work.


  1. 返回一个缺少操作数错误。

  2. 将创建新的目录,但该文件未从旧文件夹移动到新的。

我的code:

@echo off

FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO (
  SET /A MONTH=%%D
  SET /A YEAR=%%F
)

:: Set month to last month
set /a MONTH=%MONTH%-1

:: If month equals zero, reset to 12
if %MONTH%==0 set MONTH=12

:: If month < 10, fill with zero
if %MONTH% LSS 10 set MONTH=0%MONTH%

:: If month = 12, subtract one year
if %MONTH%==12 set /a YEAR=%YEAR%-1

SET FILEDATE=%YEAR%-%MONTH%

SET FOLDER2=E:\ARCHIVE\%FILEDATE%

MKDIR %FOLDER2%

:: trying to recreate the format MOVE C:\FOLDER1\\*2013-07*.* E:\FOLDER2\2013-07 which does work
MOVE C:\FOLDER1\\*%FILEDATE%*.* %FOLDER2%

:END

EXIT

编辑:下面两个反应确实帮助。我试着投他们,但我想我的名声并不好。母亲是对的 - 保护您的repuation!这将让你远。 :)

Both responders below really helped. I tried to vote them up, but I guess my reputation is not good. Mother was right - guard your repuation! It will get you far. :)

推荐答案

您应该更好地利用%DATE%,而不是 WMIC ,但你可以尝试:

You should better use %date%, not wmic, but you can try:

for /f "skip=1 delims=" %%a in ('WMIC Path Win32_LocalTime Get Month^,Year /Format:table') do for /f "tokens=1,2" %%b in ("%%a") DO SET "month=%%b" &SET "year=%%c"

这篇关于批处理文件 - 日期变量和移动文件具有可变日期的文件名从一个文件夹到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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