Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi !
I'm trying to create a script that could help me do this task, but I'm not too
good at vbscript yet.Parent directory
First Child directory
Second Child directory
|-- FileA.txt
|-- FileB.txt
|-- FileC.txt
|-- etc..
|-- etc..What I'd like that script do is to take all the files under the Second Child directory and move them up to the root of the Parent directory and delete the First and the Second
Child directory after.I think a vbscript could do this, any help would be appreciated.
Thanks

I can be done with VBS, but I find it easier to do it with a batch file. Specifically:
cd /d "Parent directory"
move "Second Child directory\*.*" .
rd "Second Child directory"

Hi Razor !
Thanks for you reply! You are right with this batch file, although, I forgot to mentioned that the directory names of the First and Second child directories are never the same.
I never know what will be the name of the directories, so I wouldn't want to hard code the script each time I want to use the script. This is why I figured that this script would work better in a VBscript.
Any help appreciated.
Thanks

@echo off
for /f "tokens=5* skip=2" %%i in ('dir ^| findstr "DIR"
') do (
move %%i\*.* .
)"Computer security." — Oxymoron

Thanks for your reply Tonysathre but unfortunately your batch file won't work !
Any help in vbscript is still welcome !

"won't work" isn't very helpful.
Try this:
======================
@echo off
setLocal EnableDelayedExpansionpushd c:\files
for /f "tokens=* delims= " %%a in ('dir/b/ad') do (
move %%a\*.*
)
=====================================
If at first you don't succeed, you're about average.M2

Hi Mechanix2Go !
Thanks for your reply, your batch file work but what do I need to add in the batch file if I want the batch file to go deeper one more level of sub-directories and move the files of that sub-sub-directory.
Right now, it does work if the files are in the first child directory (Sub-directory of the parent directory), if I have the files in the Second Child directory (Sub-Sub directory of the parent)then it doesn't work.
Also I'd like to have the First Child directory and the Second Child Directory deleted once the files have been moved to the parent directory. Clear as mud yet, isn't it ?
Any help appreciated, Thanks !

I request a rehash of the requirements, as this is what I've gotten from your posts:
1) Everything in the second (child) directory should be moved to the parent, including any directories.
2) Nothing should be moved from the first directory.
3) Presumably, the order is decided by the names of the directory.
4) Only the original first and second (child) directories should be deleted.

Hi Razor ! Thanks for your reply !
1)Indeed, the files from the second (child) directory should be moved to the parent director(two level up) including any sub-directories.
2)Nothing should be moved from the first directory(there won't be anything in it anyway!)
3)Presumably, the order is decided by the names of the directory.(That's right)
4)And yes only the original first and second (child) directories should be deleted as they will be empty after the files have been moved to the root of the parent directory.
Any help appreciated. Thanks

"4)And yes only the original first and second (child) directories should be deleted as they will be empty after the files have been moved to the root of the parent directory."
Not obvious how you'd remove 2 levels and leave others.
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |