bat当前时间文件夹
㈠ Windows和Linux下生成以当前时间命名的文件
生成以当前时间命名的文件对于当今两大主流系统都十分有用,在 Windows、Linux 操作系统,分别利用BAT批处理文件和Shell脚本,生成类似“20110228_082905.txt”以“年月日_时分秒”命名的文件。
Windows BAT批处理文件:
@echo off
set time_hh=%time:~0,2%
if /i %time_hh% LSS 10 (set time_hh=0%time:~1,1%)
set filename=%date:~,4%%date:~5,2%%date:~8,2%_%time_hh%%time:~3,2%%time:~6,2%
echo test %filename%.txt
Linux Shell 脚本:
#!/bin/sh
echo test $(date -d "today" +"%Y%m%d_%H%M%S").txt
㈡ bat创建以当前日期命名的文件夹
1、在当前文件夹内,右击新建》文本文档。
㈢ 如何批量修改文件名(bat),将一个文件夹下的所有文件加上当前时间
既然加序号,时间就仅取年月日:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir/b *.bak^|findstr/v "20[0-9][0-9][0-1][0-9][0-3][0-9]"')do (
echo %%i
set "fn=%%i"
set "t=%%~ti"
set "t=!t:~,10!"
set "nt=%%~ni_!t:-=!"
set n=100&call :yky)
pause&goto :eof
:yky
set/a n+=1
if exist "%nt%_%n:~1%.bak" goto :yky
ren "%fn%" "%nt%_%n:~1%.bak"
goto :eof