如何使用批处理作业添加文件"创建日期和QUOT;进入目录中的所有文件? [英] How to use batch job to add the file "create date" into all the files in a directory?

查看:282
本文介绍了如何使用批处理作业添加文件"创建日期和QUOT;进入目录中的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有得到一个新的文件添加到日常的文件夹与文件名相同,但增量扩展,如.001,.002 .003等文件夹但是,如果有它开始在文件夹中没有文件0.001试。

问题是他们都被命名为相同的,如果我把它们移动到另一个文件夹归档他们将只覆盖相同的文件一遍又一遍。我可以每天创建一个文件夹与中只有一个文件中的日期,但似乎有点多余。

有没有一种方式来看待每个文件的创建日期和其重命名为创建日期?

我已经得到了远,但它看起来像我这种情况必须使用一个静态的文件名,如何通过整个目录循环?

 设置文件名= C:\\ test.001
 FOR %%在f IN(%文件名%)DO filedatetime SET = %%〜TF
 重命名为C:\\ test.001 C:\\ TEST_%filedatetime%.TXT
 移动C:\\ *。txt的C:\\存档\\


解决方案

这提供了正确的排序顺序:

 关闭@echo和放大器; SETLOCAL disableDelayedExpansion
设置startfolder =%USERPROFILE%\\测试CD / D%startfolder%
对于一个%%的(*)做(
    FOR / Fdelims =。在%% B('WMIC数据文件,其中NAME =%startfolder:\\ = \\\\ \\\\%〜%%一'|。获得上次更改^找到')做(
        回声(仁%startfolder%\\ %%〜一%%〜b.txt
    )

删除回声来得到它的工作。

I have a folder that gets a new file added everyday to the folder with the same file name but incremental extension such as .001, .002, .003, etc. However, if there's no file within the folder it starts at .001 again.

The problem is they are all named the same and if I move them to another folder to archive them it would just overwrite the same file over and over again. I could create a folder each day with the date with only one file in it, but that seems a bit redundant.

Is there a way to look at the create date of each file and rename it to the create date?

I've gotten this far, but it looks like for this situation I have to use a static file name, how to loop through the entire directory?

 SET filename = C:\test.001
 FOR %%f IN (%filename%) DO SET filedatetime=%%~tf
 rename c:\test.001 C:\test_%filedatetime%.txt
 move C:\*.txt C:\archive\

解决方案

this provides the correct sort order:

@echo off &setlocal disableDelayedExpansion
set "startfolder=%userprofile%\test"

cd /d "%startfolder%"
for %%a in (*) do (
    for /f "delims=." %%b in ('wmic datafile where "name='%startfolder:\=\\%\\%%~a'" get lastmodified^|find "."') do (
        echo(ren "%startfolder%\%%~a" "%%~b.txt"
    )
)

Remove echo to get it working.

这篇关于如何使用批处理作业添加文件"创建日期和QUOT;进入目录中的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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