Solved

Move photo files based on photo names in text file

Posted on 2007-11-23
7
252 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

18 Experts available now in Live!

Get 1:1 Help Now