400 files need folders.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Calvayne
Posts: 3
Joined: 30 Nov 2009 11:15

400 files need folders.

#1 Post by Calvayne » 30 Nov 2009 11:20

I have about 400 files and I need to figure out a way to make a folder for each of them that is named based on each file's name and I need to copy the file into the matching folder. This would take hours to do manually any way I can make a batch file to do it? Thanks for the help guys.

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

#2 Post by !k » 01 Dec 2009 12:38

copy but don't move?

Code: Select all

@echo off
setlocal enableextensions

set "folder=D:\Folder\Your Folder"

cd /d %folder%
for /f "delims=" %%f in ('dir /a-d/b "%folder%"') do (
if not exist "%%~dpnf" (
md "%%~dpnf" &&copy /b "%%f" "%%~dpnf" >nul
) else echo Error: name "%%~dpnf" already exist
)
pause &exit /b

Calvayne
Posts: 3
Joined: 30 Nov 2009 11:15

#3 Post by Calvayne » 04 Dec 2009 13:02

Wow Thanks for the help. The batch file is creating all the folders and naming them correctly but it isnt moving the original files inside the appropriate folders.

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

Re: 400 files need folders.

#4 Post by !k » 04 Dec 2009 13:56

Calvayne wrote:... I need to copy the file ...

for move files replace

Code: Select all

md "%%~dpnf" &&copy /b "%%f" "%%~dpnf" >nul

to

Code: Select all

md "%%~dpnf" &&move /y "%%f" "%%~dpnf" >nul

Calvayne
Posts: 3
Joined: 30 Nov 2009 11:15

#5 Post by Calvayne » 04 Dec 2009 20:36

Thanks a ton! that works perfect and is going to save me hours. Sorry for the confusion with copy and move.

Post Reply