Commit ce1120e6 authored by Richard Torenvliet's avatar Richard Torenvliet

Update help and add a readme

parent 991a6462
## Move Files to Separate Folders:
The motivation for this small bash script is that when you want to make a big
backup of files, let's say to google drive, dropbox, icloud etc., it can simply
take forever before your files are uploaded. In my case, I wanted to backup
32000 separate files (photo's) from an external drive directly to the cloud.
This can take a couple of days to be uploaded, so the idea is to create smaller
batches so that you can also turn your computer off and continue later.
So, I wanted to move / copy these separate 32000 files into separate folders of
size `N`.
## Usage
Make part directories of size 10 (default is 10 per folder)
> 10 files
~~~shell
./mftsf.sh -i inputDir -o outputDir
~~~
Make part directories of size 500 (default is 10 per folder)
> 500 files
~~~shell
./mftsf.sh -i inputDir -o outputDir -n 500
~~~
An example of how this looks like:
~~~shell
├── folder (here all your files are located for example).
└── output
├── part_0
├── part_1000
├── part_1500
└── part_500
~~~
> Skip the first 100 and then make folders of size 100
~~~shell
./mftsf.sh -i inputDir -o outputDir -s 100 -n 100
~~~
## Disclaimer
I used this myself to make it work for my purpose, I'm not guaranteeing
anything for anyone else with respect to the result. I deliberately use the
`cp` command instead of the `mv` because I don't want to remove files. With the
skip command you can easily start off.
#!/bin/bash
N=500
N=10
#Set Script Name variable
SCRIPT=`basename ${BASH_SOURCE[0]}`
function HELP {
echo -e \\n"Help documentation for ${SCRIPT}."\\n
echo -e "Basic usage: $SCRIPT gradebook.zip"\\n
echo -e "Basic usage: $SCRIPT -o <inputDir> <outputDir>"\\n
echo "Command line switches are optional. The following switches are
recognized."
echo "-d --Set output directory. ${BOLD}$OUTPUT_DIR${NORM}."
echo -e "-h --Displays this help message. No further functions
are performed."\\n
echo "-i - Set input directory."
echo "-o - Set output directory (here all part directories will be made.)"
echo "-n - Set the size of all the part directories (how many files are \
going to be put in the new directory)"
echo "-s - How many files to skip until we start making directories and \
moving files"
echo -e "-h - Displays this help message. No further functions are performed."\\n
echo -e "Example: ${BOLD}$SCRIPT -d assignment1
gradebook.zip${NORM}"\\n
exit 1
......@@ -30,12 +34,12 @@ skip=0
while getopts :i:o:n:s:h FLAG; do
case $FLAG in
s)
skip=$OPTARG
;;
i)
findDir=$OPTARG
;;
s)
skip=$OPTARG
;;
o)
outputDir=$OPTARG
;;
......@@ -67,9 +71,10 @@ fi
echo finddir $findDir
echo outputDir $outputDir
# shift ops, all optional args are now removed $1 will have to be the filename
shift $((OPTIND-1))
#
echo "Creating folder '$outputDir' .. "
mkdir -p $outputDir
#
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment