Tyro
Tyro

Reputation: 1

Batch file to copy all subdirectory contents upwards into the parent directory?

I have a directory with a lot of text files and other bits of data that are stored in RAR files, however each RAR file (for some ridiculous reasons I cannot fathom) is stored in a directory with the same name. Thus, I have the following to work with:

Parent Directory
 >AAAAA
  >AAAAA.rar
 >BBBBB
  >BBBBB.rar
 >CCCCC
  >CCCCC.rar

Normally I could manually go in and extract each myself, but there's hundreds of these little subfolders, each with a single file in them.

What would be the most efficient way to use .bat to pull each .RAR file upwards a directory so they can be more easily selected and unpacked all at once and save me a couple hours of painful extracting?

Upvotes: 0

Views: 1456

Answers (2)

Shirulkar
Shirulkar

Reputation: 484

Following code will work for you, Just change the folder path as per your requirement

    @Echo OFF
    SET PATH1= E:\BackUp\
    FOR /F %%G IN ('DIR /b %PATH1%') DO CALL :Folders "%%G" 

    EXIT /b

    :Folders
    SET str1=%~1
    Echo %str1%
    copy %PATH1%%str1% E:\BackUp

Upvotes: 0

Dark Falcon
Dark Falcon

Reputation: 44191

Might I recommend: Use the Windows search tool to search for *.rar. Select all the results and drag them to the desired folder.

Upvotes: 2

Related Questions