随着时间的问题批处理文件之前,10:00 [英] Batch file with time issue before 10 AM

查看:148
本文介绍了随着时间的问题批处理文件之前,10:00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个批处理脚本取一个文件,将它复制到文件夹的日期和时间作为文件夹名称,然后还基于该日期和时间的文件重命名。我的问题是,之前的任何时间上午10点,该命令将失败:

I have created a batch script to take a file, copy it to a folder with the date and time as the folder name and then to rename the file also based off the date and time. My issue is that any time before 10 AM, the command fails:

c:\ICVERIFY\ICWin420\DATADIR>md C:\SettlementReports\Settlement_Reports\DATADIR\
06-25-2014_ 709_08.24.txt
A subdirectory or file C:\SettlementReports\Settlement_Reports\DATADIR\06-25-201
4_ already exists.
Error occurred while processing: C:\SettlementReports\Settlement_Reports\DATADIR
\06-25-2014_.

下面是我的批处理文件,我已经把超时错误,它之前的权利。

Here is my batch file, I have put a time out right before it errors out.

cd c:\
cd icverify
cd icwin420
cd DATADIR
:: this is Regional settings dependent so tweak this according your current settings
Echo %DATE% %Time%
Set TDate=%date:~10,4%%date:~4,2%%date:~7,2% FOR %%V IN (%1) DO Rename %%V %%V%TDate%
md C:\SettlementReports\Settlement_Reports\DATADIR\%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
timeout /T 1
copy ICRPT*.txt C:\SettlementReports\Settlement_Reports\DATADIR\%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
cd c:\
cd Settlementreports
cd settlement_reports
cd datadir
cd %date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt
ren ICRPT*.TXT ICRPT_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt

任何帮助是极大AP preciated。

Any help is greatly appreciated.

推荐答案

%TIME%变量包含空格,而不是最初的 0 左填充的小时时间小于 10点。您可以使用

Your %time% variable contains a space instead of an initial 0 left padding the hours for hours less than 10:00. You can use

set "$time=%time: =0%"

要使用替代空间 0 ,在一个新的变量存储结果值。然后更换引用%TIME%新变量%$%时间

to replace the space with a 0, storing the resulting value in a new variable. Then replace the references to %time% with the new variable %$time% as

md C:\ ....... \%date: ... %_%$time:~0,2%%$time:~3,2%_%$time:~6,5%.txt

或者相反,如果空间是没有问题的在文件名中,引用的所有文件引用,以避免错误

Or instead, if the space is not a problem in your file names, quote all the file references to avoid the errors

md "C:\Settlem .... _%time:~6,5%.txt"

对于任何两个选项,做在你的文件中的所有命令的改变引用文件/文件夹

For any of the two options, do the change in all the commands in your file referencing files/folders

这篇关于随着时间的问题批处理文件之前,10:00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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