Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for windows command or batch script to help me, i Spent 3h reading/ trying to find a solution i know its out there but my lack of scripting/programming isn't helping, hoping some can help me out.

I have a set of folders and files that i would like to bring up to the 2nd level subfolder which in this example would be subfolder1 & subfolder1 & subfolder3 etc.

D:folder>subfolder1>subfolder>subfolder>files

     >subfolder2>subfolder>files

     >subfolder3>subfolder>files

     >subfolder4>subfolder>subfolder>files
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Your goal is risky - what happens if the same file name exists in multiple subdirectoies? Only one version can exist in a given folder.

The following command prompt one liner will move files as you requested, and duplicate names will overwrite already existing files with that name:

for /d %A in ("d:\folder\*") do @(pushd "%A"&(for /r /d %B in (*) do @move /y "%B\*" "%A" 2>nul)&popd)

Or, as a batch script:

@echo off
for /d %A in ("d:\folder\*") do (
  pushd "%A"
  for /r /d %B in (*) do move /y "%B\*" "%A" 2>nul
  popd
)
share|improve this answer
    
Perfect!. it works just as intended. the files are unique so no overwriting will happen. Thank you very much. i wish superuser/stackexchange had built it "buy coffee" feature to show appreciation with more than just words. Thanks again. –  user2827759 Oct 17 '13 at 4:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.