Computing.Net > Forums > Programming > Move files to the parent directory

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Move files to the parent directory

Reply to Message Icon

Name: Desktop2k
Date: October 19, 2007 at 17:06:56 Pacific
OS: 2k
CPU/Ram: 2gb
Product: Intel
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 20, 2007 at 06:15:49 Pacific
Reply:

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"


0

Response Number 2
Name: Desktop2k
Date: October 20, 2007 at 07:23:16 Pacific
Reply:

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


0

Response Number 3
Name: tonysathre
Date: October 20, 2007 at 17:41:48 Pacific
Reply:

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

"Computer security." — Oxymoron


0

Response Number 4
Name: Desktop2k
Date: October 20, 2007 at 19:01:01 Pacific
Reply:

Thanks for your reply Tonysathre but unfortunately your batch file won't work !

Any help in vbscript is still welcome !


0

Response Number 5
Name: tonysathre
Date: October 20, 2007 at 23:56:04 Pacific
Reply:

Whats the error message?

"Computer security." — Oxymoron


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: October 21, 2007 at 02:04:10 Pacific
Reply:

"won't work" isn't very helpful.

Try this:

======================
@echo off
setLocal EnableDelayedExpansion

pushd 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



0

Response Number 7
Name: Desktop2k
Date: October 21, 2007 at 16:26:39 Pacific
Reply:

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 !


0

Response Number 8
Name: Razor2.3
Date: October 21, 2007 at 19:44:38 Pacific
Reply:

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.


0

Response Number 9
Name: Desktop2k
Date: October 22, 2007 at 17:16:58 Pacific
Reply:

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


0

Response Number 10
Name: Mechanix2Go
Date: October 23, 2007 at 15:09:22 Pacific
Reply:

"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



0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Move files to the parent directory

Batch file to check a directory is www.computing.net/answers/programming/batch-file-to-check-a-directory-is-/17337.html

batch file to copy and move certain www.computing.net/answers/programming/batch-file-to-copy-and-move-certain/11052.html

Batch file to concatenate files www.computing.net/answers/programming/batch-file-to-concatenate-files/12391.html