.bat文件更改文件名,为1天小于当前日期 [英] .bat file to change a file name to 1 day less than current date

查看:331
本文介绍了.bat文件更改文件名,为1天小于当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手在写剧本,但我知道这是可以做到我只是不知道如何...

I am a novice at writing scripts but I know this can be done I just don't know how...

我有需要有文件名更改为当前日期少1个工作日(前一个文件:周一追溯到周五,周二至周一日起静AD的prePEND

I have a file that need to have the file NAME changed to the current date less 1 workday (ex: Mondays date back Friday, Tuesdays to Monday with a prepend of the date a static "AD"

文件名例如:AD140107.pos
(星期二日期改为周三为止,AD140108.pos)
该文件位于:R:\\ PortfolioCenter \\输出\\手动接口文件

Filename example: AD140107.pos (Tuesdays date changed to a Wednesday date, AD140108.pos) The file is located at: R:\PortfolioCenter\Output\Manual Interface Files

我在有需要改变,以及日期不同的日期格式不同的文件夹类似的文件

I have a similar file in a different folder that has a different date format that needs the date changed as well

文件名例如:PC010714.slb
(星期二日期改为周三为止,PC010814.pos)
该文件位于:R:\\ slwin \\侦察调整

Filename example: PC010714.slb (Tuesdays date changed to a Wednesday date, PC010814.pos) This file is located at: R:\slwin\Recon adjustments

我想这两个文件的名称使用更改相同的脚本

I would like both file names to change using the same script

我知道DOS没有做很好平日里,所以我可以使用一个单独的文件来处理周一文件,如果neccesary

I know DOS doesn't do weekdays well so I can use a separate file to process Monday files if neccesary

推荐答案

下批子程序获取当前日期减一天的周中日期,并显示在其参数给出的格式:如果是Y,输出格式为YYMMDD,否则是MMDDYY。这个程序解决您请求的主要部分。

The Batch subroutine below get the midweek date of current date minus one day and show it in the format given by its parameter: if it is Y, output format is YYMMDD, otherwise it is MMDDYY. This routine solve the main part of your request.

@echo off
setlocal

rem If Format=Y, output is YYMMDD
rem If Format=M, output is MMDDYY

:OneMidweekDayLessCurrentDate format

rem Modify next line accordingly to your locale format (this one use DD/MM/YYYY)
for /F "tokens=1-3 delims=/" %%a in ("%date%") do set /A dd=1%%a-100, mm=1%%b-100, yyyy=%%c

rem Convert the Date minus one day to Julian Day Number, and get its Day Of Week (0=Sunday, ..., 6=Saturday)
set /A a=(mm-14)/12, jdn=(1461*(yyyy+4800+a))/4+(367*(mm-2-12*a))/12-(3*((yyyy+4900+a)/100))/4+dd-32076, dow=jdn%%7

rem If the dow is Sunday or Saturday, change it by the previous Monday
if %dow% equ 0 (
   set /A jdn-=2
) else if %dow% equ 6 (
   set /A jdn-=1
)

rem Convert the Julian Day Number back to date
set /A l=jdn+68569,n=(4*l)/146097,l=l-(146097*n+3)/4,i=(4000*(l+1))/1461001,l=l-(1461*i)/4+31,j=(80*l)/2447
set /A dd=l-(2447*j)/80,l=j/11,mm=j+2-(12*l),yyyy=100*(n-49)+i+l
if %dd% lss 10 set dd=0%dd%
if %mm% lss 10 set mm=0%mm%

rem Show the resulting date
if "%1" equ "Y" (
   echo %yyyy:~-2%%mm%%dd%
) else (
    echo %mm%%dd%%yyyy:~-2%
)
exit /B

在另一方面,你还没有指定的的文件的是要重命名的一句:我有需要有文件名改变......例如文件名的文件:AD140107.pos 。如果指定了这一点,我们就可以完成的解决方案。

On the other hand you have NOT specified which file is the one to be renamed: "I have a file that need to have the file NAME changed... Filename example: AD140107.pos". If you specify this point, we can complete the solution.

这篇关于.bat文件更改文件名,为1天小于当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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