Page 1 of 1

help please with batch move files to folder

Posted: 27 May 2011 13:17
by xassnake
hi i have a problem
i want to move winrar part files files to the same filename(folder) (witout part1 part2 etc) i have a code but if this code is not working right see image

Image


@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
set F=%%a
set F=!F:~0,9!
rem if not exist "!F!" md "!F!"
move "%%a" "!F!"
)


the filenames can change all the time with less or more characters (4 to 40)

can you tell me 'the solution?
please help

thank you

Re: help please with batch move files to folder

Posted: 27 May 2011 14:11
by orange_batch
It looks like you're trying to do:

Code: Select all

@echo off

for /f "delims=. tokens=1,*" %%a in ('dir/b/a-d') do (
md "%%a" 2>nul
move "%%a.%%b" "%%a"
)


English:
-For each file in the current directory, make a folder out of it's name up to the first period encountered. (If the folder exists, nothing happens but 2>nul makes no error display.)
-Move all files to the folder matching the name (same context).

Re: help please with batch move files to folder

Posted: 27 May 2011 14:18
by !k

Code: Select all

for /f "delims=" %%f in ('dir *.part*.rar /b/a-d') do (
  for /f "delims=." %%n in ("%%f") do (
    if not exist "%%n" md "%%n"
    move "%%f" "%%n"
  )
)

Re: help please with batch move files to folder

Posted: 27 May 2011 14:25
by orange_batch
Dare I say my solution beats yours this time !k? :P

It affects all files in the current directory though.

Re: help please with batch move files to folder

Posted: 27 May 2011 14:40
by Cleptography
Add a little if to keep the bat and yes orange you would be correct :wink:

Re: help please with batch move files to folder

Posted: 27 May 2011 15:18
by xassnake
thx for your fast answer i'll try this tomorrow morning i let you know if it works ok

Yes it works great thank you very much