help please with batch move files to folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
xassnake
Posts: 8
Joined: 01 May 2011 04:29

help please with batch move files to folder

#1 Post by xassnake » 27 May 2011 13:17

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

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: help please with batch move files to folder

#2 Post by orange_batch » 27 May 2011 14:11

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).
Last edited by orange_batch on 27 May 2011 14:23, edited 2 times in total.

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: help please with batch move files to folder

#3 Post by !k » 27 May 2011 14:18

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"
  )
)

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: help please with batch move files to folder

#4 Post by orange_batch » 27 May 2011 14:25

Dare I say my solution beats yours this time !k? :P

It affects all files in the current directory though.

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: help please with batch move files to folder

#5 Post by Cleptography » 27 May 2011 14:40

Add a little if to keep the bat and yes orange you would be correct :wink:

xassnake
Posts: 8
Joined: 01 May 2011 04:29

Re: help please with batch move files to folder

#6 Post by xassnake » 27 May 2011 15:18

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

Post Reply