I am trying to write a batch script that will run automatically compressing third subdirectories using 7-zip - directory

**[
My Pictures [First directory row]
Resized Pictures 1 [second directory row]
OriginalSizePics1 (OriginalSizePics13.zip) [Third directory row]
File21.jpg
File22.jpg
File23.jpg Resized Pictures 2 [second directory row]
OriginalSizePics2 (OriginalSizePics2.zip) [Third directory row]
File24.jpg
File25.jpg Resized Pictures 3 [second directory row]
OriginalSizePics3 (OriginalSizePics3.zip) [Third directory row]
File26.jpg
File27.jpg
]1**

Related

Concatenate two files from separate folder into multiple folder

I have folder containing files a1_1, a1_2, a2_1, a2_2, a3_1, a3_2 and folder in another directory containing b1_1, b1_2, b2_1, b2_2, b3_1, b3_2. Want to combine them into one new folder like this:
1_1 (Folder)
a1_1
b1_1
1_2 (Folder)
a1_2
b1_2
2_1 (Folder)
a2_1
b2_1
2_2 (Folder)
a2_2
b2_2
I am using UNIX, doing it one by one will be troublesome since I have 300 pairs of file that should be combined. Please help
You can easily do it using basic bash scripting, here is an example on how to do it with comments explaining the steps.
#!/bin/bash
source_dir_a=$1 // Directory containing a files given as first argument
source_dir_b=$2 // Directory containing b files given as second argument
a_files=$(ls $source_dir_a) // Save list of files in provided a dir
for a_file in $a_files; do // Loop over the files in the a dir
echo "a_file=$a_file"
folder=$(echo $a_file | sed -e 's/^a//g') // Remove the leading "a" of a files using a regex for the storing folder name
echo "folder=$folder"
b_file=$(echo b$folder) // Adding leading "b" to folder name to have b_file name
echo "b_file=$b_file"
mkdir $folder // Create output folder
mv $source_dir_a/$a_file $source_dir_b/$b_file $folder // Move the a and b files in output folder
done
What's missing is some error checking, especially if some expected files are not present.

Move files from subfolders to a parent folder

I already searched but I dind´t find a script to do what I need. Need help:
I have the situation:
Parent Folder 1
[file 1]
[file 2]
[subfolder 1]
[file 5]
[file 6]
Parent Folder 2
[file 7]
[file 8]
subfolder 2
[file 7]
Parent Folder 3
Subfolder 3
Subfolder 4
Subfolder 5
[File 8]
I just need to eliminate all subfolders and move files to parent. I already tested a script in .bat file, worked, but it need to be one by one parent folder. I it´s hundreds of parents folders.
I mean: I just need first level to keep strtucture.
I found this:
:loop for /d %%D in (%1\*) do (move "%%D\*" %1\ && rmdir "%%D") SHIFT set PARAMS=%1 if not %PARAMS%!==! goto loop
I just dragNdrop my folders and works. BUT....
Only works with first level of subfolder. I need to go deep to a few more subfolders levels.
Any ideas to improve this?

Extracting with subfolders but without parent folders

I have a zipfile structured like this:
- root
- subfolder
- subsubfolder
- file1
- file2
- file3
- file4
Using 7zip, I would like to extract the archive in such a way, that the resulting structure is:
- subsubfolder
- file1
- file2
- file3
- file4
My problem is, that neither 7z e nor 7z x accomplish this. When I use
7z x archive.zip root/subfolder
the structure doesn't change, as the files retain their full paths, and when I use
7z e archive.zip root/subfolder
the files retain no path at all, leaving me with a flat structure an an empty subsubfolder.
Edit: Unzip or any other kind of zip-tool I can use in Linux would also be fine.

Directory creation from pattern

I´ve been creating new directories manually using the script "dir.create(file.path(dir, subdir))", but now I need to automatically create new directories adopting a "pattern" 2+2 in their names, for example: directory 1 should be named "1-2", directory 2 should be named "3-4, directory 3 should be named "5-6", directory 4 sould be named "7-8", and so on...
Is this possible, buddies?

Copy files in folders by groups

I'm new to coding in Unix. I have a list of files:
output_00.txt
output_01.txt
output_02.txt
output_03.txt
output_04.txt
output_05.txt
output_06.txt
.............
output_94.txt
and a list of 10 folders:
output1
output2
output3
output4
output5
output6
output7
output8
output9
output10
I would like to copy the files .txt in the folders, so that files from output_00.txt to output_09.txt they will be in the folder "output1", files from output_10.txt to output_19.txt in the folder "output2" and so on. So, the files will be split by groups of 10 in the 10 folders.
How can I do this?
Use brace expansion for this:
for i in {1..10}
do
mv output_$((i-1))*.txt output$i/
done

Resources