0

Basically what I'm trying to do is create a folder from a filename, which this does:

for %%i in (*.png) do mkdir "%%~ni"

After folder creation I'd like move a folder into this new folder.

move "other_folder" %%~ni

1
  • Well, then go for it... Commented Jul 14, 2018 at 5:42

4 Answers 4

1

Based on your now completely changed question:

If there was only one .png file in the working directory, then you could simply do it in one line at the Command Prompt:

For %A In ("*.png") Do RoboCopy "other_folder" "%~nA" /E /MOVE >Nul 

However, if you think about it, once the other_folder has been moved the first time, it is no longer there to be moved again! You would therefore need to instead copy it, then after all .png files have been processed, remove other_folder.

At the Command Prompt: (two different commands, the first copies, the second removes)

For %A In ("*.png") Do RoboCopy "other_folder" "%~nA" /E > Nul RD /S /Q "other_folder" 

Similarly from a batch file:

@For %%A In ("*.png") Do @RoboCopy "other_folder" "%%~nA" /E > Nul @RD /S /Q "other_folder" 

Just take account that if anything goes wrong, (e.g. all of the content of other_folder doesn't copy), and you remove other_folder, you've lost that content.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this, it's useful.
1

just extend the part to be executed by DO:

for %%i in (*.png) do ( mkdir "%%~ni" convert "%%i" --folder="%%ni\test.bmp" ) 

(not sure, how your convert command works - above is a guess)

Comments

1

Based on your title request, the bellow script will create a folder named after each *.png in the directory then move the matching file into the newly created file.

Batch:

for %%i in (*.png) do (mkdir "%%~ni" && move %%i %%~ni) 

Command Prompt:

for %i in (*.png) do (mkdir "%~ni" && move %i %~ni) 

3 Comments

I want to move a different folder into the folder created by "%~ni"
Simply change the %%i to your folder name/source directory. ex: move "source dir" "%%~ni"
Please see my answer, John for a reason why the above comment should only work if there is only one .png file in the current directory.
1

Thanks everybody I was able to figure it out

for %%i in (*.png) do mkdir "%%~ni" && move "folder" "%%~ni"

1 Comment

Please see my answer for a reason why this should only work if there is only one .png file in the current directory.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.