I need to write simple script. The point is to sort the files in a folder whose name is the first letter of file name. I understand sequence of actions (get first letter of @fname; check if folder exist; create folder; move file) but i don't understand how it all write without block of code(do and end). Does forfiles blocks do/end? Or how I can write this script without block?
2 Answers
Here's another method:
@echo off
for %%a in (1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist "%%a*" md "%%a" 2>nul & move "%%a*" "%%a"
)
pause
4 Comments
Stephan
yes, but he wants a solution without
( blocks ).foxidrive
@stephen I think OP can't integrate them into Forfiles. That was an
or question, but the OP will have to return to confirm or deny. :DStephan
reading the question some times more, you may be right. Anyway, the two solutions shows clearly how powerful those blocks are.
Eugene
Thanks. I used a similar method. But instead of the set of numbers and letters I user
(*) and then used block do (). I originally wanted to use forfiles (He seemed easier) But then I figured out the for and did it all with him. Thank you.@echo off
dir /b /a-d *.* >tmp
echo END OF FILE>>tmp
echo -- start --
:loop
set /p file=<tmp
if "%file%"=="END OF FILE" goto :end
if "%file%"=="tmp" goto :ignore
md %file:~0,1%\%file% 2>nul
move "%file%" "%file:~0,1%\%file%"
:ignore
more +1 tmp >tmp2
del tmp
ren tmp2 tmp
goto :loop
:end
echo -- finish --
exit /b
Puh - I'm starting to love those blocks ^^
No need to check if the folder already exist, mdwill make it when it doesn't exist and give an error if it does exist (2>nul sends it to nirvana)
Forfilesmay not be the best tool.test.txtmove to foldert, fileexample.exeto folder namedeetc.