move files to one level up

Hi,

How can I use VBscript to achieve this?

root
  folder1
    subfolder1
       subfile1
       subfile2
    file1
    file2

  folder2
    file1
    file2


the output should be

root
  folder1
    subfile1
    subfile2
    file1
    file2

  folder2
    file1
    file2
mcrmgAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor Commented:
Here's what a basic BAT script would look like, with some comments.  Let me know how scary it looks :-).

I'll also work up a quick VBS version for you to compare to.

@echo off
REM Define base or root directory to work in
set BaseDir=c:\temp\base
REM Loop through all first level folders in base folder1
for /D %%A in ("%BaseDir%\*") do (
  REM Loop through each subfolder to the first level folders
  for /D %%B in ("%%A\*") do (
    REM Move all files from the second level to the first level
    move "%%B\*.*" "%%A"
    REM Try to remove this second level folder now
    rd "%%B"
  )
)

Open in new window

~bp
0
 
Bill PrewCommented:
This could be done quite easy in a BAT script, would that be okay, or do you require VBS?

~bp
0
 
mcrmgAuthor Commented:
either or is fine, the only thing is that I dont know that much of dos, can not modify it later.  LOL
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
mcrmgAuthor Commented:
yes, it works very well............thank you very much..........
a quick question, which line is it to delete the subfolders?  thanks
0
 
Bill PrewCommented:
he RD command (remove directory) should delete the low level folders, as long as they are empty after moving the files out (meaning no lower subfolders beyond that).

~bp
0
 
Bill PrewCommented:
And for comparison, here's aVBS approach.

sBaseFolder = "c:\temp\base"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oBaseFolder = oFSO.GetFolder(sBaseFolder)
For Each oSubFolder In oBaseFolder.SubFolders
   For Each oSubSubFolder In oSubFolder.SubFolders
      oFSO.MoveFile oSubSubFolder & "\*.*", oSubFolder & "\"
      oFSO.DeleteFolder oSubSubFolder
   Next
Next

Open in new window

~bp
0
 
mcrmgAuthor Commented:
ok. thanks
0
 
mcrmgAuthor Commented:
yes, they are doing exactly same thing..thanks again
0
 
Bill PrewCommented:
Welcome, happy to help.

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.