循环文件并移动它 [英] Loop files and move it

查看:50
本文介绍了循环文件并移动它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想创建一个批处理文件

这个批处理文件的功能是这样的



1.运行批处理文件

2.循环某个特定文件夹(C:\ pdderA)

3.找到所有。在其中的txt并获得.txt修改日期时间

4.将修改日期和时间与当前日期和时间进行比较

5.如果.txt修改日期和时间是提前3秒

6.将那些.txt移到另一个文件夹(C:folderB)



i破解我的脑袋..仍然无法得到任何想法..:S

i只能写 %%来b / b

for %%d in (C:\A) do DIR %%d *.*
pause

推荐答案

我意识到这已经很老了,但万一有人仍然感兴趣...



我认为这个问题的硬部分是关于它的秒数修改时间。事实证明forfiles会这样做,但是因为forfiles需要在一个单独的cmd shell中启动内部命令,所以返回值有点粘。



这将是将信息写入.csv文件:

I realize this is pretty old, but in case anyone is still interested...

I think the "hard" part of this is coming up with the seconds on the modified time. It turns out that forfiles will do this, but because forfiles requires internal commands to be launched in a separate cmd shell it's a bit sticky getting the values back.

This will write the information into a .csv file:
forfiles  /m *.txt /c "cmd /c for /r %%i in (@file) do @echo @file, @ftime, @fdate >> txt_files.csv"





给出.csv文件列出所有.txt文件随着日期和时间的修改,其余的应该很容易。可以使用for循环读取文件,并将日期和时间与%date%和%time%进行比较,以确定是否应移动文件。 (这一部分比棘手更繁琐:如果3秒的截止时间导致秒数超过一分钟边界,则需要调整秒数和分钟数,如果调整的分钟界限超过小时界限或者在一天的边界调整小时边界或调整的一天边界滚动一个月......你明白了。)



我看不到任何强迫的方法@time使用24小时制,因此.csv文件中的AM / PM也需要处理。



此外,%time%将在上午10点之前的任何一小时都有一个空白,所以使用以下内容将解决这个问题:



Given a .csv file listing all the .txt files along with modified dates and times, the rest should follow pretty easily. The file can be read with a for loop, and the dates and times compared to %date% and %time% to determine if the file should be moved. (That part is more tedious than tricky: if the 3-second cutoff causes the seconds to roll over a minute boundary then both the seconds and minutes will need to be adjusted, and repeat if the adjusted minute boundary rolls over the hour boundary or the adjusted hour boundary over a day boundary or the adjusted day boundary rolls over a month...you get the idea.)

I don't see any way to force @time to use a 24-hour clock, so the AM/PM in the .csv file will need to be handled as well.

Also, %time% will have a leading blank on any hour before 10 AM, so using something like the following will fix that:

set curtime=%time:~0,2%%time:~3,2%%time:~6,2%
set curtime=%curtime: =0%


这篇关于循环文件并移动它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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