S
S
sbh2018-07-24 08:12:35
cmd/bat
sbh, 2018-07-24 08:12:35

How to recursively archive each file?

There are many folders, each folder contains 1 file.
How to archive each of the files recursively with a script and delete the original one?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
res2001, 2018-07-24
@res2001

Assuming that all folders are in the same root directory (in the example c:\tmp), then something like this will be:

@echo off
set "source_dir=c:\tmp"
for /f "tokens=* delims=" %%a in ('dir /s/b "%source_dir%\*" ') do (
  rar a "%%~dpna" "%%~fa"
  del /f/q "%%~fa"
)

If the folders are scattered in different places, then you need to make changes, for example, store the list of folders in a text file or in a variable, then loop through each folder and pack. The scheme will be similar to the above script, the cycle will change a little. The option of storing the list of folders in a separate text file seems to be more preferable
. The question does not say where to write the archives. If they are written to the same place where the source files were, then when the script is called again, there will be a conflict. It is necessary to provide for skipping archive files.

A
ApeCoder, 2018-07-24
@ApeCoder

Like this (did not check) Powershell

ls -Recurse -Attributes !Directory | %{ Compress-Archive $_.FullName ($_.FullName+".zip"); rm $_.FullName}

E
Ezhyg, 2018-07-24
@Ezhyg

@echo off
for %%a in (*) do Rar.exe a -inul "%%a".rar "%%a"

and other examples

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question