Solved

move files to one level up

Posted on 2011-03-04
9
461 Views
Last Modified: 2012-06-21
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
Comment
Question by:mcrmg
  • 5
  • 4
9 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
This could be done quite easy in a BAT script, would that be okay, or do you require VBS?

~bp
0
 

Author Comment

by:mcrmg
Comment Utility
either or is fine, the only thing is that I dont know that much of dos, can not modify it later.  LOL
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 250 total points
Comment Utility
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
 

Author Comment

by:mcrmg
Comment Utility
yes, it works very well............thank you very much..........
a quick question, which line is it to delete the subfolders?  thanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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
 

Author Comment

by:mcrmg
Comment Utility
ok. thanks
0
 

Author Comment

by:mcrmg
Comment Utility
yes, they are doing exactly same thing..thanks again
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Welcome, happy to help.

~bp
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now