用于创建带有日期和子文件夹的文件夹的批处理脚本

用于创建带有日期和子文件夹的文件夹的批处理脚本

因此,我设法编写了一个脚本,创建一个带有以下日期的文件夹:

@echo off
for /f "skip=1" %%i in ('wmic os get localdatetime') do if not defined fulldate set fulldate=%%i
set year=%fulldate:~2,2%
set month=%fulldate:~4,2%
set day=%fulldate:~6,2%
set foldername=%day%.%month%.%year%
md %foldername%

现在,我需要脚本来每天创建 5 个子文件夹。任何帮助都将不胜感激。谢谢!

答案1

类似这样的:

@echo off
for /f "skip=1" %%i in ('wmic os get localdatetime') do if not defined fulldate set fulldate=%%i
set year=%fulldate:~2,2%
set month=%fulldate:~4,2%
set day=%fulldate:~6,2%
set foldername=%day%.%month%.%year%
md %foldername%\Subfolder01
md %foldername%\Subfolder02
md %foldername%\Subfolder03
md %foldername%\Subfolder04
md %foldername%\Subfolder05

答案2

对于此脚本创建的每个文件夹,请为其调用以下脚本。

Foreach($folder in Get-Content "C:\Scripts\data.txt")
{
   New-Item "C:\Scripts\$folder" -ItemType directory
}

这里的 data.txt 是任何文件或者只是父文件夹中的一个空文件。

我检查了一下并且它完美地满足了我的要求。

答案3

你可以试试:

@echo off & cd /d "%~dp0"

for /f usebackq^tokens^=1*delims^=^= %%i in (`wmic Path Win32_LocalTime Get Day^,Month^,Year /value^|find "="
   `)do if /i "%%~i" == "Year" (set "_%%~i=%%~j")else if %%~j lss 10 (set "_%%~i=0%%~j")else set "_%%~i=%%~j"

for %%i in ("Folder 1","Folder 2","Folder 3","Folder 4","Folder 5")do <con: md "%_Day%.%_Month%.%_Year%\%%~i"

或者直接在同一个mkdir命令/行中创建所有文件夹

@echo off & cd /d "%~dp0"

for /f usebackq^tokens^=1*delims^=^= %%i in (`wmic Path Win32_LocalTime Get Day^,Month^,Year /value^|find "="
   `)do if /i "%%~i" == "Year" (set "_%%~i=%%~j")else if %%~j lss 10 (set "_%%~i=0%%~j")else set "_%%~i=%%~j"

mkdir ".\%_Day%.%_Month%.%_Year%" && <con: pushd ".\%_Day%.%_Month%.%_Year%\"
mkdir ".\Folder 1" ".\Folder 2" ".\Folder 3" ".\Folder 4" ".\Folder 5" & popd 

其他资源:


相关内容