Solved

Move photo files based on photo names in text file

Posted on 2007-11-23
7
253 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now