简体   繁体   English

在几个文件夹中批量创建一组子文件夹

[英]Batch create a set of subfolders in several folders

My goal is to create a set of folders with identical subfolders. 我的目标是创建一组具有相同子文件夹的文件夹。 I need one folder for every year since 1881, each year-folder should contain a folder per month, and each month-folder should contain a folder per day. 自1881年以来,我每年都需要一个文件夹,每个文件夹每年应包含一个文件夹,每个文件夹每天应包含一个文件夹。

I have found a tool to create the folders for the years, my challenge now is to populate them with the subfolders. 我已经找到了多年创建文件夹的工具,现在的挑战是在子文件夹中填充这些文件夹。 I want to do this on a Windows client computer, preferably without installing anything. 我想在Windows客户端计算机上执行此操作,最好不要安装任何内容。

What I have been working on, is using the FOR and MD commands to do the job. 我一直在努力,使用FOR和MD命令来完成这项工作。 Here's the code I have so far: 这是我到目前为止的代码:

SET %g=*.*
FOR /d %var IN %path% DO MKDIR 01 02 03

Whenever I run this, I get this error: 每当我运行此命令时,都会出现此错误:

%path% was unexpected at this time 目前%path%意外

So, that is where I am stuch right now. 所以,这就是我现在要去的地方。 I'd appreciate any help you can give me! 我会很感激您能给我任何帮助!

Excuse me PA Your solution is right, I just couldn't resist the temptation to add some code to create the right number of days per month. 对不起,PA您的解决方案是正确的,我无法抗拒添加一些代码以创建每月正确天数的诱惑。

@echo off
setlocal EnableDelayedExpansion
set m=0
for %%d in (31 28 31 30 31 30 31 31 30 31 30 31) do (
   set /A m+=1
   set daysInMonth[!m!]=%%d
)
pushd d:\dest
for /L %%y in (1881,1,2012) do (
   mkdir %%y
   pushd %%y
   for /L %%m in (1,1,12) do (
      mkdir %%m
      pushd %%m
      set days=!daysInMonth[%%m]!
      if %%m == 2 (
         set /A yMod4=%%y %% 4, yMod100=%%y %% 100, yMod400=%%y %% 400
         if !yMod4! == 0 (
            set /A days+=1
            if !yMod100! == 0 if not !yMod400! == 0 (
               set /A days-=1
            )
         )
      )
      for /L %%d in (1,1,!days!) do (
         mkdir %%d
      )
      popd
   )
   popd
)
popd

Previous code add 1 day to February in leap years, that is, if the year is divisible by 4, but at centurial years only if it is also divisible by 400. 1600 and 2000 were leap years, but 1700, 1800 and 1900 were not. 以前的代码在leap年中将1天加到2月,即如果年份可以被4整除,则只有在百年中还可以被400除以百年。1600和2000是leap年,而1700、1800和1900则不能。

first, read HELP FOR and then to begin with something, try this in a command line 首先,请阅读“ HELP FOR ,然后从命令行开始,在命令行中尝试

  for /l %a in (1881,1,2012) do @echo %a

now you're wet already, add some spice 现在你已经湿了,加一些香料

  for /l %a in (1881,1,2012) do @for /l %b in (1,1,12) do @echo %a-%b

and you're almost done 而且你快完成了

  for /l %a in (1881,1,2012) do @for /l %b in (1,1,12) do @for /l %c in (1,1,31) do @echo %a-%b-%c

the only thing left is to transform your echo into the appropiate mkdir and adding some incantation to translate it into a BAT file.... 剩下的唯一一件事就是将您的echo转换为适当的mkdir并添加一些咒语以将其转换为BAT文件。

@echo off
pushd d:\dest
for /l %%a in (1881,1,2012) do (
  mkdir %%a
  pushd %%a
  for /l %%b in (1,1,12) do (
     mkdir %%b
     pushd %%b
     for /l %%c in (1,1,31) do (
       mkdir %%c
     )
     popd
  )
  popd
)
popd

but, be warned, this will grow extremely crazy! 但是,请注意,这将变得极其疯狂!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 批量创建文件夹和子文件夹 - Creating folders and subfolders in batch 如何批量合并两个文件夹,包括子文件夹 - How to merge two folders including subfolders in batch 如何使用批处理脚本使用另一个目录的子文件夹名称在目录中创建新的空文件夹? - How can I create new empty folders in a directory using names of subfolders of another directory using batch script? 基于多个文件名批量创建多个文件夹,并将多个相关文件移动到创建的文件夹中 - Batch Create Several Folders Based on Multiple Filenames, and Move Multiple Related Files to The Created Folders 批处理:遍历文件夹和子文件夹并将其放入脚本 - Batch: Looping through folders and subfolders and get them into a script 批处理文件,它计算特定目录下的所有文件夹和子文件夹 - Batch file which counts all folders and subfolders on specific directory 批处理文件以生成100个文件夹,每个文件夹中有100个子文件夹 - Batch file to generate 100 folders with 100 subfolders within each folder 批量重命名多个文件夹中的所有文件 - Batch Renaming All Files in Several Folders 批量创建子文件夹并将父图像文件复制到新的子文件夹 - batch create subfolders and copy parent image files to new subfolders 批处理文件以创建多个文件夹和子文件夹 - Batch file to create multiple folder and subfolders
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM