Hello!
I am trying to organize a lot of folders contained within the same folder, most of them follow this standard when it comes to the folder name:
"(code) XXX NAME (Source) XXX"
//XXX represents random text that may be present.
// The first parenthesis is not always present either.
So, for example, I have a folder named "(C323) Fox (Carnivore)" within my folder "Animals" and need for the batch to take the contents within the last parenthesis and make a folder with that name (if it doesnt exist already) and move the orignal folder "(C323) Fox (Carnivore)" to the new folder "Carnivore".
I have tried looking on stackoverflow and even asking myself, since all the similar things i find are for file names instead of folder names, I cant make it work.
I noticed what I was asking is very similar to topic=152980.0 posted by doshisahil95 on this very forum, just that its a folder name and the folder name would be that of the parenthesis.
Is this at all doable?
I include my failure at making my own code, just for some laughs:
@echo off
setlocal enabledelayedexpansion
for %%A in (*) do (
echo directory found %%A
for /D "delims=" %%B in ("%%A") do set fname=%%~nB
for /D "delims=" %%C in ("%%A") do set fextn=%%~xC
for /D "tokens=1* delims=()" %%D in ("!fname!") do set folname=%%D
echo folder name !folname!
if not exist "!folname!" (
echo Folder !folname! does not exist, creating
md "!folname!"
) else (
echo Folder !folname! exists
)
echo Moving file %%A to folder !folname!
move "%%A" "!folname!"
)
echo Finished
pause
I have some other attempts based on other posts i've found, if they help let me know!