It might be a duplicate of this but I need a little revision: Creating a folder from first 5 characters of filename in a batch file

I don't need to select the first five letters of the file. I want the folder name to be exactly the same as the file name. And I want it to happen in the folder wherever the batchscript is located. So it must detect the current folder.

Any easy way to modify the original script?

EDIT: Actually not much modification is needed. However when it creates the folders it includes the file extension. Is there a way to remove the file extension?


Using ~n includes only the filename without the extension.

You don’t even need a whole batch file, just the following line is enough:

for %i in (*) do md "%~ni"

It must be run from the target directory though, so the current directory is irrelevant because md "%~ni" defaults to creating the directory in the current working directory.

If you want to run it from any directory and pass it the target (e.g., create a shortcut that you can drag-and-drop folders to), then you can use this (e.g., Files2Folders.bat):

@for %%i in (%1\*) do md "%1\%%~ni"

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.