Thanks for all your help! That did help a bit, at least got me started on the right foot. So I changed things a bit (see below). However, when I run it the first 23 files don't end up in a directory, and it all ends up in a directory called DTI5. Is there anyway to count the files and after counting them say move file #1 thru #23 to directory DTI1, move file #24 thru #46 to directory DTI2, and so on AND THEN tell it to stop counting at file number 92 if there happens to be more files in the source directory???
#!/bin/csh
# Here are the variables that you will need to change:
################################################################################
mkdir DTI1
mkdir DTI2
mkdir DTI3
mkdir DTI4
set number_of_files = 23 # This is the number of files that you expect
# to store in each directory
set source_dir = ./ # changed this to the current directory I want it run in (has all 92 files)
set target_dir = DTI # This is the prefix that you'll use for your
# folder tree. You'll likely wish to change it
# Here are the 'static' variables that you will not change:
################################################################################
#this number will increment the count cap
set count = 0
#iteration counters
set folder_counter = 1 # Starts at one, such that multiplication issues don't arise
set counter = 0
# Get your list of files - (I don't want them by date, they are already in order so I just list them)
foreach file ( `ls $source_dir` )
@ counter = $counter + 1
@ count = $number_of_files * $folder_counter #First time 'round, this is 3, then 6
# First, check to see if you should move on to the next folder or not...
# - adding a 'move' request to ensure that the file is not skipped
if ($counter > $count) then
@ folder_counter++
mv $source_dir/$file $target_dir$folder_counter
endif
# Since you didn't need to increment the folder_counter - move the file as if nothing happened...
if ($counter <= ($count)) then
mv $source_dir/$file $target_dir$folder_counter
endif
end