Answer» Hello everyone,
I have a script:
Code: [Select]FILE$i=`ls ~/Desktop/File_Converted/` mkdir /tmp/$FILE mv ~/Desktop/PIX_Converted/* /tmp/$FILE/$FILE The I do some stuff to the file. When I am done doing that stuff I delete the directory and the file. This is fine as far as it goes, but the problem is that if another file is dropped into File_Converted directory before I am doing doing stuff to the file I am currently working with it will change the value of the $FILE variable before the script has completed which will mess up the stuff I am doing with the file.
What I'd like to do is use a variable set up where the variable is, say, $FILE1. I check to see if $FILE1 is defined and, if not, use it. If it is defined, then try $FILE2, etc... In the end, when I am done, I want to RECLAIM the variable so $FILE1 get set back to null again and the next file dropped in can use it again.
Any help would be greatly appreciated. I'm new to this so I don't know where to begin.
Thanks!
Dan How about using a loop instead of numbering the files? Something like this:
Code: [Select]FCDIR=~/Desktop/File_Converted for FILE in $FCDIR/*; do
# Remove the FINAL slash and everything before it NAME="${FILE##*/}" mkdir "/tmp/$NAME" || exit mv -v "$FILE" "/tmp/$NAME/"
# Do processing ... done Note that I used quotes to allow for NAMES with SPACES, but if you're sure no filenames have spaces, you could leave them out.
|