Solved

Move photo files based on photo names in text file

Posted on 2007-11-23
7
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

622 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