×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Find then copy files from Network Server to local folder from a CSV file (Mac OS X)

Find then copy files from Network Server to local folder from a CSV file (Mac OS X)

Find then copy files from Network Server to local folder from a CSV file (Mac OS X)

(OP)
Hi

I'm having real problems and hope you can help me?

I wish to search my network backup server (NAS) for images that are listed in a CSV file (one per line - i.e.: 0001.jpg) once found a copy to placed in a local folder on my Mac (/RESULTS/)

I have managed to get this to work but only works on the root folder of the server, I can't get it to search all sub-folders on the Backup have tried -r & --recursive but neither are working!

Here's the code Ive been using:

rsync -r --files-from=‘/Users/AndiZu/Desktop/ebay2.csv’ /Volumes/Studio-1/ /Users/AndiZu/Desktop/RESULTS/

ebay2.csv = List of files to search for

/Volumes/Studio-1/ = Path to my backup server

/Users/AndiZu/Desktop/RESULTS/ = Local folder where files should be copied to!


Thank you in advance!

AndiZu

RE: Find then copy files from Network Server to local folder from a CSV file (Mac OS X)

AndiZu,
I would do something like this. You may have to play with the paths to make it work.
Disclaimer: I know almost nothing about the Mac OS, so I have no idea if these commands will work properly or not.
Good luck!

CODE --> Powershell

## These are going to have to be changed to match your environment
$search_files_path = "/Users/AndiZu/Desktop/ebay2.csv"
$source = "/Volumes/Studio-1/"
$dest = "/Users/AndiZu/Desktop/RESULTS/"

## Check for search files path existence
try
	{$search_files_path_found = Test-Path $search_files_path}
catch
	{
	 write-host ""
	 write-host "Search file ($source) cannot be found." -foregroundcolor "red"
	 write-host ""
	}

## Check for source existence
try
	{$source_found = Test-Path $source}
catch
	{
	 write-host ""
	 write-host "Source path ($source) cannot be found." -foregroundcolor "red"
	 write-host ""
	}

## Check for destination existence
try
	{$dest_found = Test-Path $dest}
catch
	{
	 write-host ""
	 write-host "Destination path ($dest) cannot be found." -foregroundcolor "red"
	 write-host ""
	}

if ($dest_found -AND $source_found -AND $search_files_path_found)
	{
	 ## Import search files
	 $search_files = import-csv $search_files_path
	 
	 ## Get all files on the source
	 $all_files = Get-ChildItem -Path $source -Recurse | where {!($_.psiscontainer)}

	 ## Look for the files you want copied
	 foreach ($file in $search_files)
		{
		 $filename = $file.Name
		 write-host $filename
		 $file_found = $all_files | where {$_.name -match $filename}

		 ## Determine how many files were found
		 $count = $file_found.Count

		 switch ($count)
			{
			 1
				{
				 $file_path = ($file_found.VersionInfo).FileName
				 write-host "`t$file_path"
				 Copy-Item -Path $file_path -Destination $dest -Force
				 break
				}
			 0
				{
				 write-host "`tFile not found" -foregroundcolor "red"
				 break
				}
			 default
				{
				 write-host "`tMultiple files found!" -foregroundcolor "yellow"
				 foreach ($found in $file_found)
					{
					 $file_path = ($found.VersionInfo).FileName
					 write-host "`t   $file_path" -foregroundcolor "yellow"
					}
				 break
				}
			}
		}
	} 


Light travels faster than sound. That's why some people appear bright until you hear them speak.

RE: Find then copy files from Network Server to local folder from a CSV file (Mac OS X)

(OP)
Hi blister911

Thanks for this but it didn't seem to work! It didn't throw back any errors but didn't copy / move any of the images!

Thanks anyways!

Andi

RE: Find then copy files from Network Server to local folder from a CSV file (Mac OS X)

I think it might be a difference between our input files. My file names column has a header of "Name", which I reference in the script.

CODE --> File-Example

Name         <--- Header
File1.jpg    <--- File
File2.gif    <--- File
File3.txt    <--- File
File4.doc    <--- File 


Light travels faster than sound. That's why some people appear bright until you hear them speak.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close