Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 470
  • Last Modified:

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
0
mcrmg
Asked:
mcrmg
  • 5
  • 4
1 Solution
 
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
 
Bill PrewCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now