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
Solved

Deleting a file from the coldfusion server

Posted on 2008-10-16
6
157 Views
Last Modified: 2013-12-16
How do I delete a file directly after it has been selected for download?  Everything I keep doing ends up deleting the entire directory or just a specific file.  

I'm sorry if this is a stupid question.
0
Comment
Question by:dthomas06
  • 3
  • 2
6 Comments
 
LVL 36

Expert Comment

by:SidFishes
ID: 22732912
can you post a code snip?
0
 

Author Comment

by:dthomas06
ID: 22732986
<cfloop query="getfile">
   <cfif Type IS "Dir">
     <a href="#cgi.SCRIPT_NAME#?DirPath=#url.DirPath#\#name#&CaseN=#url.CaseN#"><img src="../images/folder.gif" width="19" height="17" border="0"> #name#</a>
     <cfelse>
    #name#<a href="NewIndex3_VOpenFile.cfm?filepath=#url.DirPath#%5C#name#" target="_blank"> Download</a> <cffile action="delete" file="#url.DirPath#%5C#name#">
</cfif>         
  <br>
</cfloop>
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 22732990
it is not a stupid question, just a very unclear one:
- what do you mean by "after is has been selected for download"? when exactly is this moment? where in your application logic does this happen?
- post the code you are currently using to delete the file, and it will be easier for everyone to see where the problem may be.

"Everything I keep doing ends up deleting the entire directory..." - not good
"... or just a specific file." - sn;t this what you want, to delete a specific file?
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:dthomas06
ID: 22733321
Sorry it's not clear.  

After the people log in to the system and click to see what files are available for download a list is pulled of Files located on a section of our directory.  As soon as they click download on a specific file or several minutes after the fact they want the file to be deleted from the directory.  

As far as the specific file being deleted the only way that happens is when I plug in the files name in the tag <cffile action="delete" file="#url.DirPath#%5C#name#">.  

0
 
LVL 27

Accepted Solution

by:
azadisaryev earned 100 total points
ID: 22733590
thanks, it is much clearer now.

an obvious problem for you here is that you have no idea if the file has finished downloading or not. a slow connection, network congestion and a bunch of other factors can play a role in download speed. this gets more important with file size increase.

so, a couple of ways to proceed here. both ways will require an intermediary page, so your links for downloading should not link directly to the files, but to this intermediary page, passing a reference to the file to be downloaded to it in some way (url var, session var, etc). the function of this intermediary page will depend on the way you choose to serve up your files for downloading:

a) you can, through a combination of cfheader and cfcontent tags, 'stream' the file to your user, which will prompt him/her to save the file to their computer. the cfcontent tag has a deleteFile attribute which, hen set to "yes" deletes the file from the server after sending it to the user's browser.
an example of this would be:
<cfheader name="Content-Type" value="application/pdf">
<cfheader name="Content-Disposition" value="attachment; filename=mypdf.pdf">
<cfcontent type="application/pdf" file="C:\pdfs\mypdf.pdf" deletefile="Yes">

the above, or something similar, would be the content of the intermediary page in this case.

b) another option is to store the info about which files have been selected for downloading and when somewhere (db, application scope, a text file, etc), and then configure and run a schedule task that will delete all the files that have been recorded X time units ago, i.e. run a task every 30 minutes that deletes all files that have been stored as selected for download more than 10 minutes ago (assuming 10 minutes is enough to download your largest file over the slowest connection).

in this case the intermediary page will record the requested file and the time of request and then can just cflocation to the actual file.

hth
0
 

Author Comment

by:dthomas06
ID: 22733835
Thank you so much azadisaryev.  I just did it and it worked.  I was concerned about a file downloading quick enough and said numerous times that we needed to make sure the file would complete downloading as we are looking at files over 40 MB.  
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

860 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