Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

move files to one level up

Posted on 2011-03-04
9
Medium Priority
?
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 57

Expert Comment

by:Bill Prew
ID: 35039868
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
ID: 35039886
either or is fine, the only thing is that I dont know that much of dos, can not modify it later.  LOL
0
 
LVL 57

Accepted Solution

by:
Bill Prew earned 1000 total points
ID: 35039951
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:mcrmg
ID: 35039987
yes, it works very well............thank you very much..........
a quick question, which line is it to delete the subfolders?  thanks
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 35040116
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 57

Expert Comment

by:Bill Prew
ID: 35040168
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
ID: 35040210
ok. thanks
0
 

Author Comment

by:mcrmg
ID: 35040232
yes, they are doing exactly same thing..thanks again
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 35041226
Welcome, happy to help.

~bp
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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