Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Move photo files based on photo names in text file

Posted on 2007-11-23
7
Medium Priority
?
263 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 2000 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
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

824 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