# Thread: arrgg!  I need to copy files from....

1. ## arrgg!  I need to copy files from....

Hi All,
This sounds like it would great for ruby, (I know you will read this GnuVince) but I don't have ruby installed, this is running under cygwin, i have perl and bash shell scripts at my disposal. I am sure C could also do it pretty easily, but I know damn little about C system calls, we just can't use 'em in an embedded environment.

The problem:
I have a directory will 1500+ files in it, they get updated frequently. I have sorted out many of these files in seperate directories to make it a bit more managable in about 15 directories. when the updates come in i need to find each file and put it in the correct directroy. I did a ls &gt; fileslist thinking my awk skills were 1/10 what they used to be, unfortunaltey what I tried failed miserably.

the question:
How do I have the files listed in the list get copied to a another directory without doing each one by hand? I tried an awk thing but failed, a couple of redirection commands, a pipe....

2. ## Re: arrgg!  I need to copy files from....

How about some shell scripting ?

If you wan't to keep the files that has been changed, but also like the new ones to be attended, and you want to look the whole drictory tree through..

Code:
#!/bin/bash

# first make sure no files that were touched on last run will be moved.
cp -f new_file_list old_file_list

# find the new files there
ls -l &gt; new_file_list

# sort out, which are the new ones
# or have been changed since last and do what ever
for i in ls -l &#124; grep -v --file=old_file_list &#124; awk '{print $NF}' \ &#124; grep -v old_file_list &#124; grep -v new_file_list; do # what ever command you want done to$i
done
I know theres a better way to do the final grep -v thingys.. But I can't remember the correct syntax.

I forgot, this will also catch the directories, if you want to omit them, then use ls -lF &#124; grep -v /  instead of the ls -l

4. ## Re: arrgg!  I need to copy files from....

I'm not 100% if this is what you wanted to do...

1. You have a dir with subdirs containing files to be updated
2. You have a bunch of new versions of these files in ./
3. You want to find where the old version is and copy a new version over it
4. ./filelist contains the list of new files

This will do the job I've described (hopefully what you wanted ? ).

$cat filelist &#124; ./myscript Code: #!/bin/bash while read in_arg do { find /path/to/oldfiles -name$in_arg -exec cp \$in_arg '{}' \;
}
done
First real bash shell script in my life

5. ## Re: arrgg! *I need to copy files from....

the question: *
How do I have the files listed in the list get copied to a another directory without doing each one by hand? *I tried an awk thing but failed, *a couple of redirection commands, *a pipe....
You must suffer. Just kidding. I'd use xargs for such a task.

cat list &#124; xargs -i{} cp {} /new/dir

6. ## Re: arrgg! *I need to copy files from....

If you are in win32, why bother with the cygwin and whatnot.. .just do it as a batch file (foo.bat)

Code:
Echo on

REM * Create a list of files

DIR \your\path\to\dir\*.* /B &gt; files.txt

REM * Create a file to hold the results of each process
Echo &gt; log.txt

FOR /F %%A IN (files.txt) DO CALL copy %%A \apth\to\new\place &gt;&gt; backup_log.txt

DEL files.txt

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•