loop through directories and move files

I need help creating a vbs that will
loop through all subdirecotories of a directory called images and move all the files within all the subdirectories to the main directory called images.
once the directory is empty it should delete it  (but never delete files - only move them to the main directory)

can someone help me with this
bottomlinemgAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

divyeshhdoshiCommented:
SUB MOVEFILES(FILE DIR)
        FOREACH FILE F IN DIR.FILES
               IF(F.ISDIRECTORY)
                   MOVEFILE(DIR,F)
                    F.DELETE();
               ELSE
                    F.MOVE(DIR)
      NEXT
END SUB

SUB MOVEFILE(FILE ROOT, FILE CURRENT)
   FOREACH FILE F IN CURRENT.FILES
            IF(F.ISDIRECTORY)
                 MOVEFILE(ROOT,F)
                 F.DELETE()
             ELSE
                  F.MOVE(ROOT)
  NEXT
END SUB

hi THIS CODE MAY HAVE SYNTAX ERRORS,
Regards,
Divyesh Doshi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shift-3Commented:
This is easier to do in batch than in vbscript; recursing subdirectories with a WMI query is possible (as in http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0218.mspx) but cumbersome.

Copy the script below into a new file with a .cmd extension.  Change the value of the "root" variable to the path of the images directory.  Running the script will move all subfiles up to the images folder and delete any empty folders.

If there are any duplicate files then they will not be moved and their folders will not be deleted.


@echo off
setlocal enabledelayedexpansion
 
set root=c:\images
 
for /F "tokens=* usebackq" %%G in (`dir "%root%" /A:D /B`) do (
 for /F "tokens=* usebackq" %%H in (`dir "%root%\%%G" /A:-D /B /S`) do (
  echo N|move /-Y "%%H" "%root%"
 )
)
 
for /F "tokens=* usebackq" %%G in (`dir "%root%" /A:D /B`) do (
 set contents=
 for /F "tokens=* usebackq" %%H in (`dir "%root%\%%G" /A:-D /B /S 2^>NUL`) do (
  set contents=%%H
 )
 if not defined contents rd /q /s "%root%\%%G"
)

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.