Windows - 批处理文件,如何循环或重复子程序?

Windows - 批处理文件,如何循环或重复子程序?

我想要 13 个文件夹:一个主文件夹“Folder_A”和十二个月的其他十二个子文件夹(这是财务方面的事情)。我的批处理文件代码分配了 Folder_A 属性。我希望这些属性对其他十二个文件重复。如何循环执行此操作?现在,我只知道复制粘贴十二次并更改文件夹名称,天哪,但我需要对许多其他文件夹 A、B、C、D 等执行此操作……如何分配/设置重复到十二个子文件夹的文件夹属性?

创建文件夹

@ECHO OFF  

PUSHD "%~dp0"  
MKDIR "Folder_A"  
ATTRIB +S "Folder_A"  
ATTRIB -R "Folder_A"  
ATTRIB -H -R "Folder_A\BLUEA.ini.ico"  
ATTRIB -H -R "Folder_A\Desktop.ini"  
COPY /Y "BLUEA.ini.ico" "Folder_A\BLUEA.ini.ico"  
ECHO [.ShellClassInfo] > "Folder_A\Desktop.ini"  
ECHO IconFile=BLUEA.ini.ico >> "Folder_A\Desktop.ini"  
ECHO IconIndex=0 >> "Folder_A\Desktop.ini"  
ECHO InfoTip=Apples Apples Apples >> "Folder_A\Desktop.ini"  
ATTRIB +H +R "Folder_A\BLUEA.ini.ico"  
ATTRIB +H +R "Folder_A\Desktop.ini"  
ATTRIB +R "Folder_A"  
POPD  

MD Folder_A\2019_01
MD Folder_A\2019_02
MD Folder_A\2019_03
MD Folder_A\2019_04
MD Folder_A\2019_05
MD Folder_A\2019_06
MD Folder_A\2019_07
MD Folder_A\2019_08
MD Folder_A\2019_09
MD Folder_A\2019_10
MD Folder_A\2019_11
MD Folder_A\2019_12

EXIT

答案1

假设文件夹图标应该随着你的字母而改变,那么这个带有嵌套 for 和(代码块)的批次可能会执行以下操作:

:: A:\Test\SU_1442422.cmd
@ECHO OFF  

PUSHD "%~dp0"
For %%F in (A B C D) Do (
    MKDIR "Folder_%%F"  
    ATTRIB    -R "Folder_%%F"  
    ATTRIB -H -R "Folder_%%F\BLUE%%F.ini.ico"  
    ATTRIB -H -R "Folder_%%F\Desktop.ini"  
    COPY /Y "BLUE%%F.ini.ico" "Folder_%%F\"  

    ( ECHO [.ShellClassInfo]  
      ECHO IconFile=BLUE%%F.ini.ico
      ECHO IconIndex=0
      ECHO InfoTip=Apples Apples Apples
    ) > "Folder_%%F\Desktop.ini"

    for %%M in (01 02 03 04 05 06 07 08 09 10 11 12) do (
        MKDIR     "Folder_%%F\2019_%%M"
        ATTRIB +R "Folder_%%F\2019_%%M"
    )

    ATTRIB +H +R "Folder_%%F\BLUE%%F.ini.ico"  
    ATTRIB +H +R "Folder_%%F\Desktop.ini"  
    ATTRIB +S +R "Folder_%%F"  
)
POPD

在此处输入图片描述

相关内容