0

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.

  • If there is a way to force it to repeatedly retry until successful, I feel like that would be a hacky way out of having to supervise the moving around of the tens of thousands of images I have to move. – Sammy Mohamed Jul 31 '12 at 01:14
  • just offering an alternate view to your problem here, would it makes sense to write 2 (or more) scripts that handle each of the special cases that you identified? This would simplify the logic, if each problem set can be solved separately. Also, don't forget that shell has test operators like `if [[ -f $file ]] ; then echo "$file exists" ; else echo "no $file found"; fi` that could help you control the flow of your program. Good luck. – shellter Jul 31 '12 at 02:35
  • Yeah I guess I can include that... but I was feeling skeptical because if its breaking after downloading so few at a time, there must be some bigger issue I'm missing. It can't just be the extra copy failures... or can it? Anyway I'm really hoping there is an elegant solution because I've already spent so much time organizing this set of files... X_X – Sammy Mohamed Jul 31 '12 at 10:34
  • Just to reiterate my first idea, you wrote 'not all the folders are in this exact format'.... can you process just the folders that ARE in the exact format with one script, and then process 'one other type' separately. (Without a test harness to see exactly what your script is doing, it's hard to understand from your description.). You might want to post this to a cygwin-specific support group, as I believe there are special issues with cygwin that you won't see in the same script run on Unix/Linux. Also might help to include version of Cygwin and bash in your main message. Good luck. – shellter Jul 31 '12 at 17:57

0 Answers0