Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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