Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CF -File import check

Posted on 2011-03-08
15
Medium Priority
?
312 Views
Last Modified: 2012-05-11
I have the following procedure where if the import file exists then the import procedure runs and the file is moved to an archive folder and then the file is deleted since another import would mess up the data.  Then a email is generated informing that it has run. There is just one import per day.  We have found out that sometimes another file is sent in error.  What I am trying to do is check the archive folder for testfile.csv and if the file date is equal to Now() then do not run the procedure since that means that it is today's file import and it has already run and also to send a email alerting that another file is trying to import.  

Any help is appreciated.
<cfif FileExists("C:\Inetpub\wwwroot\testfile.csv")>

		
		  
	   <cffile action="read" file="C:\Inetpub\wwwroot\testfile.csv" variable="csvfile"> 
		<cfloop index="record" list="#csvfile#" delimiters="#chr(10)##chr(13)#">

Import procedure


<cffile action="copy" source="C:\Inetpub\wwwroot\testfile.csv" destination="C:\Inetpub\wwwroot\dataarchive\testfile.csv">
		<cffile action = "delete" file = "C:\Inetpub\wwwroot\testfile.csv"> 

<cfmail to="DBA@company.com"
					from="webmaster@company.com"
					subject="file complete successful"
					type="text">
				file complete successful
	</cfmail>

Open in new window

0
Comment
Question by:JohnMac328
[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
  • 8
  • 5
  • 2
15 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 35072458
if the file date is equal to Now()

If by you mean the file exists and has today's date, try something like this.  Or you could modify it to check the last 24 hrs instead.

<cfset isNewFile = true>
<cfset filePath = "C:\Inetpub\wwwroot\testfile.csv">
<cfif FileExists(filePath) >
    <!--- if it was uploaded today --->
    <cfif dateCompare(now(), GetFileInfo(filePath).FileLastModified, "d") eq 0>
         <cfset isNewFile = false >
     </cfif>
</cfif>

<cfif isNewFile >
     .... do processing ...
</cfif>
0
 

Author Comment

by:JohnMac328
ID: 35072541
At this point don't I need to check if it is true or false before processing?

<cfif isNewFile >
     .... do processing ...
</cfif>
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 35072545
<cfdirectory
DIRECTORY="C:\Inetpub\wwwroot\"
NAME="mydirectory"
FILTER="testfile.csv">

<CFOUTPUT query="mydirectory">#DateLastModified#</CFOUTPUT>
0
How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

 
LVL 39

Expert Comment

by:gdemaria
ID: 35072552
oops, posts crossed
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35072557
At this point don't I need to check if it is true or false before processing?

That's what it does. It's shorthand for saying

<cfif isNewFile eq true>
    it's okay to do processing
</cfif>
0
 

Author Comment

by:JohnMac328
ID: 35072591
It has a problem with this

Element FILELASTMODIFIED is undefined in a CFML structure referenced as part of an expression.  
 
 
The error occurred in C:\Inetpub\wwwroot\: line 25
 
23 :
24 : <cfif FileExists("C:\Inetpub\wwwroot\")>
25 :     <cfif dateCompare(now(), GetFileInfo(filePath).FileLastModified, "d") eq 0>

 
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35072653
<cfif FileExists("C:\Inetpub\wwwroot\")>

That's not a file, it's a directory.  Both functions require the CSV file path

<cfif FileExists("C:\myFileName.csv")>
   <cfif dateCompare(now(), GetFileInfo(C:\myFileName.csv).FileLastModified, "d") eq 0>
....
0
 

Author Comment

by:JohnMac328
ID: 35072666
I removed the actual file names for security reasons, it is a valid path I am working with.
0
 

Author Comment

by:JohnMac328
ID: 35072686
If you can delete the post I can post the actual code I have
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35072711
No, only moderators can do that.  But best not to post it at all.  Btw: you could always replace the path with "c:\path\to\dummyFileName.csv".

Anyway, are you running CF8+?  If you're on MX7 you'll have to use cfdirectory.  Otherwise, maybe CF8 doesn't like the direct variable access.  Try this instead


<cfset isNewFile = true>
<cfset filePath = "C:\Inetpub\wwwroot\testfile.csv">
<cfif FileExists(filePath) >
    <!--- if it was uploaded today --->
    <cfset csvInfo = GetFileInfo(filePath )>
    DEBUGGING: <cfdump var="#csvInfo#">
    <cfif dateCompare(now(), csvInfo.FileLastModified, "d") eq 0>
         <cfset isNewFile = false >
     </cfif>
</cfif>

.... rest of code
0
 

Author Comment

by:JohnMac328
ID: 35072781
The dump showed all the file information correctly and then gave this error

      Element FILELASTMODIFIED is undefined in CSVINFO.

<cfif dateCompare(now(), csvInfo.FileLastModified, "d") eq 0>  
0
 

Author Comment

by:JohnMac328
ID: 35072787
Using CF8
0
 

Author Comment

by:JohnMac328
ID: 35072812
Here is shows last modified

struct
canRead YES  
canWrite YES  
isHidden NO  
lastmodified {ts '2011-03-08 13:11:56'}  
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 35072969
Sorry my bad. The field name is "lastModified" not "FileLastModified".  

ie Should be
<cfif dateCompare(now(), csvInfo.LastModified, "d") eq 0>  
0
 

Author Closing Comment

by:JohnMac328
ID: 35073054
That seemed to work, thanks as always agx!
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

722 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