Passing Directory Name with spaces in it

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
parodytx
Posts: 1
Joined: 25 Feb 2011 19:29

Passing Directory Name with spaces in it

#1 Post by parodytx » 25 Feb 2011 19:52

Newbie problem perhaps but I cannot find a solution even after searching the board.

An unpacker program created a directory that was supposed to be a bunch of individual files. Instead it created a couple of thousand directories names similar to the file names with spaces and sometimes dashes in them. Each directory contains a single file similar to the the directory name:

Toplevel
Name of first directory
\Name of first directory file.pdf
Name - of second directory
\Name - of second directory file.pdf
...
etc.

I would like to create a batch file to recursively send the directory name to a second batch file that moves the file to Toplevel, then deletes the directory names.

Any assistance would be greatly appreciated.

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

Re: Passing Directory Name with spaces in it

#2 Post by !k » 26 Feb 2011 04:46

Code: Select all

@echo off &setlocal enableextensions
for /d /r %%d in (*) do call :up "%%d"
goto :eof

:up
move "%~1\*" "%~dp1" &&rd /q %1 2>nul
goto :eof

place in Toplevel & run

Post Reply