There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Batch file assistance


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
robertnevill's Avatar
Junior Member with 5 posts.
 
Join Date: Nov 2002
22-Aug-2005, 06:05 AM #1
Batch file assistance
I need to create a batch file, which locates all files with a particular extension and moves them several levels up in the folder structure. Here is the situation. My zip utility extracted numerous archives, RAR archives within a ZIP files. Each archive was extracted with a default path, which create three or four levels of folders. The last folder level contains the extracted files.

I want to copy these files into a folder 4 levels up and delete the extraneous folders. The manual approach seems doable, yet two hours later I found myself with ¼ way through. These directories number in the hundreds.

Then I thought a batch file could simplify the solution. But I only have fundamental experience with batch files. Please let me know if anyone could provide me with some assistance and lead me in the right direction.

How do you move multiple files with different file extensions (like *.doc, *.txt, *.htm)? How do you count the number of child directories so the batch file moves the files up to the parent folder? How do you search recursive folders in a directory?

For illustration purposes, the folder hiearchy follows below. I need to get all text, html, and doc files from ArchiveNameAgain into ArchiveName. I need a batch file since the scenario exist for a couple hundred archive folders.

uncompressing\ArchiveName\UnZipArchive\UnRAR\ArchiveNameAgain\files.txt, file.htm

Here’s my starting point.

@ECHO ON
REM This batch file should search for recursive directory and extract the files from the last
REM final folder level; and move the files a specific number of folders up.


F:
CD Uncompressing\


:AGAIN
ECHO MOVING %1
MOVE %1\%1\*.*
REM DELTREE /Y %1
SHIFT
IF NOT "%1" == "" GOTO AGAIN

ECHO

Last edited by robertnevill : 22-Aug-2005 06:08 PM.
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
23-Aug-2005, 12:43 AM #2
I suspect that what you want to do is impossible in DOS/Command Console scripting, without some third-party add-ons. For example, the MKS Toolkit brings many Unix/Linux utilities to DOS/Command Console and would certainly allow you to do what you want to do. Within DOS/Command Console however, I suspect you will not be able to do what you need.

Hope this helps -- and hope I'm wrong! ().
__________________
The slowest component still sits at the keyboard.
robertnevill's Avatar
Junior Member with 5 posts.
 
Join Date: Nov 2002
24-Aug-2005, 08:37 PM #3
Code:
@echo ON

SET "dir=f:\uncompressing"
SET "ext=*.doc *.txt *.htm"

FOR /r "%dir%" %%* IN (%ext%) DO (
  MOVE "%%*" "%%~dp*..\..\")
FOR
* Used to repeat a command on a group of files / drives.
* SYNTAX -:
o FOR /r "%dir%" %%* IN (%ext%) DO (
echo ^
move "%%*" "%%~dp*..\..\")
+ WHERE :
# %%* is a variable name
# (%ext%) is a group of files
# move is a command that is to be repeated for each member of list.


I am almost there with this batch file. It does the job, yet could use additional modifications. Upon activating the batch file, it runs through the recursive directories; identifies the files; and moves them up two levels. The issue occurs in the folders where I already manually performed these tasks. The batch file moves these files outside the "uncompressing" folder and creates a mess. I could try and separate these folders; but will miss a few.

I wonder if it possible to include the following functionality. If these text files are four levels deep, move them up three levels; if three levels exist, move them up two levels; if two levels exist move them up one level; if one level exist don't move anything.

I need the files to end up in the Archive folder (different names for each archive); NOT the uncompressed folder; not the root dirve. Let me know if anything is possible.

f:\uncompressing\Archive\document.txt

f:\uncompressing\Archive\Unzip\document.txt

f:\uncompressing\Archive\Unzip\UnRAR\document.txt
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:16 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.