Solved

Move photo files based on photo names in text file

Posted on 2007-11-23
7
256 Views
Last Modified: 2012-05-05
I have a list of photos that contains the names of photos that I would like to separate from a large directory of photo files. Since this would be a time consuming project to perform by hand I would like to automate the process with Coldfusion. What I want to do is put together a Coldfusion script that when run will look at the photo names in a text file and then check to see if they are present in the master photo directory. If a photo listed in the list is found in the photo directory Coldfusion would then copy each photo it finds to a new directory. Does anyone have code that could perform this task?

Here is a sampling of photo names in the text files and the photo names match exactly the photo names in the master photo directory.
0
Comment
Question by:CalDev
  • 4
  • 3
7 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 20341314
Did you accidentally omit the sampling in the original post?
0
 

Author Comment

by:CalDev
ID: 20341323
Yes I did thank you for pointing it out.

_DSC0505.JPG
_MG_4015.jpg
100_2773.jpg
5589 - Train Tracks.jpg
1095965492_m.jpg
Camp 2006 108.jpg
Fly.JPG
Hodley Peak.jpg
IMG_0438.jpg
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 20341357
Caveat - This example as some debugging code in it.  

1) It prints a message if the file doesn't exist
2) If the file already exists in the destination directory, it does _not_ overwrite it.  You can change that if you prefer
<!--- read list of photos --->
<cffile action="read" file="c:\yourDirectory\listOfPhotos.txt" variable="fileContent">
<!--- directories must end with "\" --->
<cfset sourceDirectory = "c:\yourDirectory\">
<cfset destinationDirectory = "c:\otherDirectory\">
<cfloop list="#fileContent#" index="fileName" delimiters="#chr(13)##chr(10)#">
	<cfif FileExists("#sourceDirectory##fileName#")>
		<cfif NOT FileExists("#destinationDirectory##fileName#")>
			<cffile action="copy" 
				source="#sourceDirectory##fileName#" 
				destination="#destinationDirectory##fileName#">
		<cfelse>
			<cfoutput>
			Error. File #fileName# already exists om #destinationDirectory#<br>
			</cfoutput>
		</cfif>
	<cfelse>
		<cfoutput>Skipped. File not found ... #sourceDirectory##fileName#<br></cfoutput>
	</cfif>
</cfloop>

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:CalDev
ID: 20341418
Another home run! Worked perfectly and I really like the reporting feature you added, that was a big plus!
Again this one worked perfectly the very first time. I was amazed how fast I was able to process over 1400 files even on our slow local network. Thanks so much!
0
 

Author Closing Comment

by:CalDev
ID: 31410728
Very useful code for verifying and separating files. It is so well written that I believe it could be easily modified to perform other file tasks.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 20341463
Yes, for moderate size files it does pretty well :)
0
 
LVL 52

Expert Comment

by:_agx_
ID: 20341499
Btw, I'm sure you noticed it does a "copy" of the files, not a "move".  I think is what you wanted.  If you wanted to "move" the files instead, change the code to

<cffile action="move" ...>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question