问题描述
我有一个目录树与数千个pdf和tifs。一个文件夹可能包含多个pdf或tif,在这种情况下,它们被编号为1.pdf,2.pdf等...我必须使它们可用,并确保它们是最初处理最旧的文件 - 所以我想重命名他们与他们创建日期和时间(1.pdf - > 20150415481876.pdf):目前我使用
@echo off
set datetime =%〜t1
set name =%〜n1
set extension =%〜x1
set year =%datetime: 〜6,4%
set month =%datetime:〜3,2%
set day =%datetime:〜0,2%
set hour =%datetime:〜11,2%
set min =%datetime:〜14,2%
ren%1%year %% month %% day %% hour %% min %% name %% extension%
现在可以将文件1.tif正确地重命名为2014052513241.tif(文件创建25.05.2014 13:24)。但是,如果我使用batch.bat * .tif调用批处理,我如何能够处理同一文件夹中的多个文件(例如1.tif 2.tif 3.tif)?
谢谢
@if(@X)==(@ Y)@end / * JScript注释
@echo off
setextension = tiff
setdirectory = c:\somedir
pushd%directory%
setlocal enableDelayedExpansion
for %% a in(*%extension%)do(
for / f %%#in('cscript // E:JScript // nologo%〜f0%% a')设置cdate = %%#
echo ren%% a!cdate!%%〜xa
)
rem cscript // E:JScript // nologo%〜f0%*
exit / b%errorlevel%
@if(@X)==(@ Y )@end JScript注释* /
FSOObj = new ActiveXObject(Scripting.FileSystemObject);
var ARGS = WScript.Arguments;
var file = ARGS.Item(0);
var d1 = FSOObj.GetFile(file).DateCreated;
d2 =新日期(d1);
var year = d2.getFullYear();
var mon = d2.getMonth();
var day = d2.getDate();
var h = d2.getHours();
var m = d2.getMinutes();
var s = d2.getSeconds();
var ms = d2.getMilliseconds();
if(mon< 10){mon =0+ mon;}
if(day< 10){day =0+ day;}
if h(10){h =0+ h;}
if(m if(s< 10){s =0 + s;}
if(ms< 10){ms =00+ ms;} else if(ms
WScript .Echo(+年+ mon + day + h + m + s + ms);
设置自己的扩展名和目录,将目录中给定扩展名的所有文件重命名为创建日期。格式将是 YYYYMMDDhhmm
.Renaming是 echo
ed,所以你可以看到一切是否正常。如果它是删除 echo
第九行。
I have a directory tree with thousands of pdfs and tifs. A folder may contain multiple pdfs or tifs in that case they are numbered 1.pdf, 2.pdf etc... I have to make them available and making sure they are maually processed oldest files first - so I want to rename them with their creation date and time (1.pdf -> 20150415481876.pdf):
Currently I use
@echo off
set datetime=%~t1
set name=%~n1
set extension=%~x1
set year=%datetime:~6,4%
set month=%datetime:~3,2%
set day=%datetime:~0,2%
set hour=%datetime:~11,2%
set min=%datetime:~14,2%
ren %1 "%year%%month%%day%%hour%%min%%name%%extension%"
This can now properly rename a file 1.tif to 2014052513241.tif (file created 25.05.2014 13:24). But how can i make this able to handle multiple file in the same folder (e.g. 1.tif 2.tif 3.tif) if i call the batch with batch.bat *.tif?Thank you
@if (@X)==(@Y) @end /* JScript comment
@echo off
set "extension=tiff"
set "directory=c:\somedir"
pushd "%directory%"
setlocal enableDelayedExpansion
for %%a in (*%extension%) do (
for /f %%# in ('cscript //E:JScript //nologo "%~f0" %%a') do set "cdate=%%#"
echo ren "%%a" "!cdate!%%~xa"
)
rem cscript //E:JScript //nologo "%~f0" %*
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */
FSOObj = new ActiveXObject("Scripting.FileSystemObject");
var ARGS = WScript.Arguments;
var file=ARGS.Item(0);
var d1=FSOObj.GetFile(file).DateCreated;
d2=new Date(d1);
var year=d2.getFullYear();
var mon=d2.getMonth();
var day=d2.getDate();
var h=d2.getHours();
var m=d2.getMinutes();
var s=d2.getSeconds();
var ms=d2.getMilliseconds();
if (mon<10){mon="0"+mon;}
if (day<10){day="0"+day;}
if (h<10){h="0"+h;}
if (m<10){m="0"+m;}
if (s<10){s="0"+s;}
if (ms<10){ms="00"+ms;}else if(ms<100){ms="0"+ms;}
WScript.Echo(""+year+mon+day+h+m+s+ms);
set your own extension and directory to rename all files with given extension in directory to their creation date.The format will be YYYYMMDDhhmm
.Renaming is echo
ed so you can see if everything is ok.If it is remove the echo
word from the 9th line.
这篇关于重命名文件与创建日期& Windows批处理时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!