2

If that title wasn't confusing enough.. hopefully what I am trying to do is a lot simpler to understand.

Windows 7 just in case it needs to be said.

I have multiple directories within the folder I am working in;

C:\WorkingDir\1
C:\WorkingDir\2
C:\WorkingDir\3
and so on

Within each of these folders (1,2,3,etc) is a single sub-directory and no other files or folders;

C:\WorkingDir\1\5E04AB
C:\WorkingDir\2\4F07FC
C:\WorkingDir\3\9DA04F

I need to move each of those single subdirectories from within the parent folder to a new folder;

C:\NewFolder\5E04AB
C:\NewFolder\4F07FC
C:\NewFolder\9DA04F

That's it! I thought it might be simple, but I can't wrap my head around the variables or a better resource explaining how to use them. I don't use batch files much if at all, so I am very sorry for this cry for help. Hopefully someone more knowledgeable has a simple explanation that can help me out :-)

I found this: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true

But can someone link me to a resource where I can learn more about batch variables and parameters for future reference?

Thank you thank you thank you

Update:

@endoro Thanks for your response. There must have been a user error the first time I tried to run your code. It is working properly and all is well! Thank you so much!

Update 2 After running the code User1 contributed, It will create my NewFolder directory, but will not copy anything to it. It remains empty. Here is some of the repetitive output in DOS when I run it:

C:\WorkingDir>(
set fldr2=C:\WorkingDir\1\5E04AB
 move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.

C:\WorkingDir>(
set fldr2=C:\WorkingDir\2\4F07FC
 move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.

C:\WorkingDir>(
set fldr2=C:\WorkingDir\3\9DA04F
 move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.`
pnuts
  • 58,317
  • 11
  • 87
  • 139
element6
  • 43
  • 6
  • Ok, I tried this but am only getting "The syntax of the command is incorrect" whenever I try to run it. `@echo off` `&setlocal` `set "workingdir=C:\WorkingDir"` `md "C:\NewFolder" 2>nul` `pushd "%workingdir%"` `cd` `for /d %%i in (*) do for /d %%j in ("%%~i\*") do echo move "%%~fj" "C:\NewFolder\%%~nxj"` `popd` – element6 Apr 17 '13 at 18:50
  • Do you want a fix for this specific set of folders, or for this problem in general? – user1 Apr 17 '13 at 19:17

2 Answers2

0

Please look at the output and remove the echo, if it is OK:

@echo off &setlocal 
set "workingdir=WorkingDir"
md "C:\NewFolder" 2>nul

pushd "%workingdir%"
cd
for /d %%i in (*) do for /d %%j in ("%%~i\*") do echo move "%%~fj" "C:\NewFolder\%%~nxj"
popd
Endoro
  • 37,015
  • 8
  • 50
  • 63
  • I can't figure out how to get my comments to display properly spaced and everything when I reply.. I was using the back ticks around my code, but it isn't showing my spacing and line breaks correctly. http://stackoverflow.com/editing-help#need-more-detail didn't help either.. – element6 Apr 17 '13 at 19:03
  • I checked the code, it's OK here. Do you see the output from the `cd` command? This should show `C:\WorkingDir`. – Endoro Apr 17 '13 at 19:26
  • Works for me, too - I copied OP's version directly. Only change was the drive letter I used. – Magoo Apr 17 '13 at 19:37
  • Ahhh! I don't know what I did the first time around but yes, it is working flawlessly. Thank you! – element6 Apr 17 '13 at 20:12
0

I haven't been able to test this but:

@echo off
setlocal EnableDelayedExpansion
md "c:\NewFolder\"
cd "C:\WorkingDir\"
for /D /r %%a in ("*") do (
    set fld1=%%a
    cd "%fld1%"
    for /D /r %%b in ("*") do (
        set fld2=%%b
        move "c:\WorkingDir\%fld1%\%fld2%" "C:\NewFolder\%fld2%"
        )
    )

And a good resource for batch:

http://ss64.com/nt/

user1
  • 153
  • 1
  • 8