I want 13 folders: One main folder "Folder_A" and twelve other sub-folders for the twelve months (it's a finance thing). My batch file code assigns Folder_A attributes. I want these attributes to repeat for the other twelve files. How to do this in a loop? Right now, I only know to copy-paste twelve times and change folder names, omg, but I need to do this for many other folders A, B, C, D, etc... How to assign/set folder attributes repeating to the twelve sub-folders?



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"  

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


Assuming the folder icons should change with your letters, this batch with nested for and (code blocks) might do:

:: A:\Test\SU_1442422.cmd

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"  

enter image description here

| improve this answer | |
  • OMG, this is so awesome!! Thank you LolPings!!! – SofiaEd May 31 '19 at 1:37
  • Sorry LotPings... misspelled your alias above.... I want to learn more DOS commands!! – SofiaEd May 31 '19 at 2:43
  • Never mind, you can always delete your comments ;-) BTW The Windows command prompt is NOT a DOS prompt! – LotPings May 31 '19 at 8:51
  • Hi LotPings... Quick question... For the above code, I would like to make the root directory (such as "C:\" a variable, so that I can do this for C:\ and D:\ and E:\ and F:\ etc.... How to do adjust the code above to do this? – SofiaEd Jun 11 '19 at 2:03
  • The batch takes it's own location as the base, so simply copy/move it (and the icon files) where you want the folders to be created. – LotPings Jun 11 '19 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.