I have a folder with about 100 subfolders. In each of these subfolders, there are 4 text files and either 1 or 2 folders containing images and 4 currently empty folders corresponding to the 4 text files. In each text file, there is a list of images that need to be moved from an image folder into a specific folder.
Here is an illustration:
/Textures/Asymmetrical/ contains
/Asymmetrical/
/Asymmetrical+Texture/
/1/ /2/ /3/ /4/
/1.txt /2.txt /3.txt /4.txt
In 1.txt, there are a list of files that need to go from /Textures/Asymmetrical/Asymmetrical/ OR /Textures/Asymmetrical/Asymmetrical+Texture/ into /Textures/Asymmetrical/1/ and so on.
But not all the folders are in this exact format -- there is one other type illustrated below:
/Textures/Zigzagged/ contains
/images/
/1/ /2/ /3/ /4/
/1.txt /2.txt /3.txt /4.txt
The purpose of these files/folders should follow from above, except this is simpler to work with as it only has 1 image folder.
Now I wrote the following code in shell:
filename='1.txt' #I was going to do the text files one at a time..
#Hidden: I set the value of filename2 to another text file.
while read f;
do
while read g;
do
cp ./$f""/images/$g $f""/2_Good/
cp ./$f""/$f/$g $f""/2_Good/
cp ./$f""/$f""+texture/$g $f""/2_Good/
done < $f""/$filename
done < $filename2
Now this actually does work, but it will produce a lot of errors since some folders do have the images subfolder and some others don't and so on. But I can totally live with that. The bigger issue is that the program gives up after a while, perhaps after copying somewhere around 40-200 images. I have many tens of thousands of images to move so I can't be bothered to do the copying in chunks of this size. I get an error that looks like:
8 [main] -bash 5796 fork:child -1 - forked process 5764 died unexpectedly, retry 0, exit code -1073741819, errno 11
./moveAround.sh: fork: retry: Resource temporarily unavailable
./moveAround.sh: fork: Resource temporarily unavailable
So I guess I'm asking for either 1) A fix to my code OR 2) A general solution to this problem that can work with little supervision.