0

I have very limited if any knowledge of coding. So I'm not sure if this can be done through creating a batch file.

I'm on Windows 10 btw.

I have a large database of 'client' folders. Perhaps this would be the parent folder, if not.. There are subfolders within for each letter of the alphabet which is the first letter for each client name. So it would go

C:Client/A/Adams, Bill

C:Client/A/Anderson, Jill

C:Client/B/Burgundy, Jack

..and so on. There are thousands of clients.

Under each and every specific client folder (adams, bill etc) I need to create a subfolder called ID & PFP

Is there are batch I can create to automatically go through all the lettered subfolders and the subsequent client subfolders within those and create the 'ID & PFP' subfolders inside every single client name?

Furthermore some of said subfolders have a folder called 'ID' already. Is there a code that could say create those subfolders within client name folders - if there is no folder called 'ID'.. If there is folder called 'ID' rename it to 'ID & PFP'?

Very kind regards

  • Yes, this can be done using the md command which is used to Make Directory. – spikey_richie Oct 18 at 7:28
  • edited my answer so it also included the case with the ID subfolder – veritaS Oct 18 at 9:31
0

The following batch is what you need.
edit: added subfolder "ID" case

@echo off
setlocal
  for /f  %%b in ('dir /b /a:d') do (
      rem enter the directory
      pushd %%b
      echo In Directory: %%b

    for /f  %%c in ('dir /b /a:d') do (
      rem enter the directory
      pushd %%c
      echo In Directory: %%c

      IF EXIST ID (
        rem Folder "ID" does exist 
        echo Folder "ID" Renamed to "ID & PFP"
        rename "ID"  "ID & PFP"
        ) ELSE (
        rem Folder "ID" does not exist
        rem create folder
        md "ID & PFP"
        echo Folder: "ID & PFP" created
      )


      rem leave the directory
      popd
     )
      rem leave the directory
      popd
  )
  pause >nul
endlocal

Put this into a batch file and put it into the parent folder where you have the folder a,b,c etc....

Basically this script will go into every sub folder in which it is in and then go into every next sub folder benethe to create a folder.

In Directory: test
In Directory: child
Folder "ID" Renamed to "ID & PFP"
In Directory: child1
Folder: "ID & PFP" created
In Directory: child2
Folder: "ID & PFP" created
In Directory: test1
In Directory: child
Folder: "ID & PFP" created
In Directory: test2
In Directory: child
Ein Unterverzeichnis oder eine Datei mit dem Namen "ID & PFP" existiert bereits.
Folder: "ID & PFP" created
0

Well, the following code will do everything You asked for, please feel free to copy it inside of some ".txt" editor and save it with ".bat" extension(for example: "dirHelper.bat").

Don't forget to change a second line from "CD C:\root" to something that corresponds to your case - "CD C:\Client" and feel free to ditch the "echo" statements I have added them just to help you understand what's going on while you are testing or for log purposes on execution

@Echo Off
CD C:\root 
echo entered %cd% directory
FOR /D %%G in ("*") DO (
    CD %%G 
    echo entered %cd%\%%G directory
    FOR /D %%N in ("*") DO (
        cd %%N
        echo entered %cd%\%%G\%%N directory
        if EXIST ID (
            rename ID "ID & PFP"
            echo Found ID folder inside %cd%\%%G\%%N
            echo ID folder renamed to "ID & PFP"
            CD ..\
        ) else (
            if EXIST "ID & PFP" (
                echo "ID & PFP folder already exist here:" %cd%\%%G\%%N
                CD ..\
            ) else (
                md "ID & PFP"
                echo created "ID & PFP" folder inside %cd%\%%G\%%N directory
                CD ..\

                )
        )
    )
    CD ..\
)
PAUSE

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.