Deleting all files in a directory

Hi,
Is it possible to use cffile to delete all files in a
directory. I have a function that creates a file in seperate parts
and places the finished file into a folder. But I need a check to
delete all files currently existing in said folder. I understand it
is possible to query a folder for existing files and then use that
query with cffile to delete the files... I just don't know how to
do it.
Thanks for your help

I am not postivie, but I think I recall learning that the
delete all function is prohibited via CF. You can delete specific
files, though.
If this is, in fact, the case, you could query the directory,
and then loop through the resultant query, deleting each file one
at a time.

Similar Messages

  • Delete all files in a directory not working for some files

    I have a requirement like wants to delete all the files in a directory. (These files got generated through some other program.)
    Problem is file.delete() is returning false for some of the files..
    (donno the reason .. could be bcoz of file closing issues/locking issues.)
    Looking for a solution where i can delete a file forcefully irrespective of whether the file is opened or not.
    Thanks
    Srini

    are you on windows? if so, it's almost impossible to delete something another process has open.

  • How to delete all file in a directory

    Hi,
    Myself is Lokesh....can anyone tell me how can we delete all existing mail file which i kept in linux (PATH IS: /usr/share/mailfile/)...the mail file extension is *.MAIL. Please help me in sortout this problem...

    See listFiles (FileFilter) and delete ().

  • How to remove all files in a directory in java?

    I have tried method delete() of File ,
    but no effect!
    can anyone help me!
    thank you

    So, you have a directory and you want to delete all files in the directory. Here is some (untested) code:
    File dir = new File("C:\\tempdir");
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length; ++i) {
      if (files.isFile()) {
    files[i].delete();
    Jesper

  • Can i delete ALL files in directory ?

    i create a upload test using FileReference & PHP.
    In this scenario user upload files to http server.
    Now how can i delete all files in /files/uploads folder in AS3
    AS3 Code:
    req = new URLRequest();
    req.url = ( stage.loaderInfo.parameters.f )? stage.loaderInfo.parameters.f : "http://www.website.com/test/upload.php";
    uploadFile = new FileReference();
    select_btn.addEventListener( MouseEvent.CLICK, browse );
    uploadFile.addEventListener( Event.COMPLETE, complete_func );
    uploadFile.addEventListener( DataEvent.UPLOAD_COMPLETE_DATA, show_message );
    function browse( e:MouseEvent )
              filefilters = [new FileFilter('Images',"*.jpg;*.png;*.gif")];
              uploadFile.browse( filefilters );
    function complete_func( e:Event )
              trace( 'complete !' );
    function show_message(e:DataEvent)
    if (e.data == 'ok')
              label_txt.text = 'The file has been uploaded.';
    else if ( e.data == 'error')
              label_txt.text = 'The file could not be uploaded.';
    PHP Code:
    <?php
    $uploads_dir = './files/uploads';
    if( $_FILES['Filedata']['error'] == 0 ){
              if( move_uploaded_file( $_FILES['Filedata']['tmp_name'], $uploads_dir.$_FILES['Filedata']['name'] ) ){
                        echo 'ok';
                        exit();
    echo 'error';
    exit();
    ?>

    You need call another PHP file
    <?php
       $directory = './files/uploads';
       getDirectoryList ($directory);  
       //This function find all the files in the directory
       function getDirectoryList ($directory)
         // create an array to hold directory list
         $results = array();
         // create a handler for the directory
         $handler = opendir($directory);
         // open directory and walk through the filenames
         while ($file = readdir($handler)) {
           // if file isn't this directory or its parent, add it to the results
           if ($file != "." && $file != "..") {
        //$results[] = $file;
         // Delete Files
        $filename = $file;
      unlink($filename); //this delete a file
         // tidy up: close the handler
         closedir($handler);
    ?>

  • I previously had PS CS5 Trial installed but removed it using both Control Panel Programs and deleting all files from the CS5 directory on Program Files.  I then installed a purchased product from Adobe disc using the serial number on the case.  But when I

    I previously had PS CS5 Trial installed but removed it using both Control Panel Programs and deleting all files from the CS5 directory on Program Files.  I then installed a purchased product from Adobe disc using the serial number on the case.  But when I try to launch it, I get a screen headed Photoshop CS5 Extended Trial.  It asks for the serial number and says that my trial has expired.  It rejects the serial number from the Adobe case saying "This Serial Number is not valid for this product".  It thinks that I still have the expired Trial Version installed.  How do I convince it (the program) that the Trial Version is long gone and the currently installed product was installed with a valid and accepted serial number????

    Let me know how it goes. Go into your Adobe account and register your serial number asap.
    https://www.adobe.com/account/my-products-services.html
    That way, should you lose it or you need support, it is on record that it's yours and you can fetch your s/n it from anywhere.
    There are too may sad stories here, where people forgot and the box is buried or lost.
    Gene

  • [Bash] Massively replace text in all files of a directory

    Hi everybody,
    I wrote this small recursive function in order to massively replace some strings contained in all files of a directory (and all subdirectories). Any suggestions?
    replaceText() {
    # set the temporary location
    local tFile="/tmp/out.tmp.$$"
    # call variables
    local script="$2"
    local opts="${@:3}"
    browse() {
    for iFile in "$1"/*; do
    if [ -d "$iFile" ];then
    # enter subdirectory...
    browse "$iFile"
    elif [ -f $iFile -a -r $iFile ]; then
    echo "$iFile"
    sed $opts "s/$(echo $script)/g" "$iFile" > $tFile && mv $tFile "$iFile"
    else
    echo "Skip $iFile"
    fi
    done
    browse $1
    Syntax:
    replaceText [path] [script] [sed options (optional)]
    For example (it will replace "hello" with "hi" in all files):
    replaceText /home/user/mydir hello/hi
    Note: It is case-sensitive.
    Bye,
    grufo
    Last edited by grufo (2012-11-10 15:05:43)

    falconindy wrote:
    Yes, find is recursive and extremely good at its job.
    http://mywiki.wooledge.org/UsingFind
    Well
    falconindy wrote:Your lack of quoting is dangerous, as is your code injection in sed. I'm not sure why you're echoing a var inside a command substitution inside a sed expression, but it's going to be subject to word splitting, all forms of expansion, and may very well break the sed expression entirely, leading to bad things. A contrived example, but passing something like 'foo//;d;s/bar/' should effectively delete the contents of every file the function touches.
    So, if you consider it dangerous, you can adopt the whole "sed syntax" and confirm before continue...:
    replaceText() {
    # set the temporary location
    local tFile="/tmp/out.tmp.$$"
    # call variables
    local sedArgs="${@:2}"
    browse() {
    for iFile in "$1"/*; do
    if [ -d "$iFile" ];then
    # enter subdirectory...
    browse "$iFile"
    elif [ -f $iFile -a -r $iFile ]; then
    echo "$iFile"
    sed $sedArgs "$iFile" > $tFile && mv $tFile "$iFile"
    else
    echo "Skip $iFile"
    fi
    done
    while true; do
    read -p "Do you want to apply \"sed $sedArgs\" to all files contained in the directory $1? [y/n] " yn
    case $yn in
    [Yy]* ) browse $1; break;;
    * ) exit;;
    esac
    done
    Syntax:
    replaceText [parent directory] [sed arguments]
    Example:
    replaceText /your/path -r 's/OldText/NewText/g'
    or, if you want to work directly with the current directory...
    replaceText() {
    # set the temporary location
    local tFile="/tmp/out.tmp.$$"
    # call variables
    local sedArgs="$@"
    browse() {
    for iFile in "$1"/*; do
    if [ -d "$iFile" ];then
    # enter subdirectory...
    browse "$iFile"
    elif [ -f $iFile -a -r $iFile ]; then
    echo "$iFile"
    sed $sedArgs "$iFile" > $tFile && mv $tFile "$iFile"
    else
    echo "Skip $iFile"
    fi
    done
    while true; do
    read -p "Do you want to apply \"sed $sedArgs\" to all files contained in the directory $PWD? [y/n] " yn
    case $yn in
    [Yy]* ) browse $PWD; break;;
    * ) exit;;
    esac
    done
    Syntax:
    replaceText [sed arguments]
    Example:
    replaceText -r 's/OldText/NewText/g'
    What about?
    falconindy wrote:I'll also point out that declaring a function within a function doesn't provide any amount of scoping -- 'browse' will be declared in the user's namespace after running this function for the first time.
    See:
    function1() {
    function2() {
    echo "Ciao"
    function2
    function2 # error
    function1 # works

  • Anyone knows how to delete a file from a directory?????

    hi there
    anyone has any idea on how to delete a file from a directory? delete(String filename)? thank you.

    Hi,
    Check this link.
    Gives you an example code to show how to delete a file.
    http://examples.oreilly.com/jenut/Delete.java
    Hope this helps.
    Roopasri Vittal
    Developer Technical Support
    Sun Microsystems
    http://sun.com/developers/support

  • Can I delete all files and users (including admin account) without re-installing SL?

    I have a 1st generation Macbook Air, running Snow Leopard 10.6.8.  Just bought myself a new MBA, want to sell the old one (privately, not soliciting here).
    The original install disks were Leopard.  I bought a family pack SL and upgraded the MBA at that point.  Earlier this year I sold my old Mac Mini (when I upgraded) and included the SL install disks with that sale (stupid of me).
    Now I want to sell the old MBA.  Ideally, I'd have a clean install on SL on it, minus all previous files and accounts.  I've done that before when selling old computers, reformatted / erased the HD, then reinstalled the OS.  But I don't have the SL disk anymore, and I don't really want to pay for it just to prep this notebook for sale.
    AFAICT, my options are:
    wipe the HD and reinstall Leopard (the only OSX disks I have).  Whoever buys it from me would need to upgrade to SL themselves, and from there to Lion if they want.
    somehow try to delete all files and users without touching the current install of SL.  I'm not terribly worried about security of what little information is on the MBA (nothing important to me), so I don't mind trashing files and then emptying trash instead of wiping the HD block by block. 
    Any ideas for how to do #2?  I can trash all files/folders under /user, uninstall all applications and delete their folders from Library, uninstall all browsers except Safari and wipe the history from that...
    Is there other stuff I should be deleting?  plist files, maybe?  I'm leery of messing around too much and disrupting the install of the underlying OS.
    Can I also delete the admin account (or rename it "admin" with a generic default password?)?
    Any other suggestions?  Thanks.

    Trashing files you have created is relatively easy. Getting rid of an account is a bit harder. Trashing the .plist files, etc., that may contain personal info is a lot harder, and there is always the risk that you will miss something.
    Best, and easiest, and customary, is to do option #1 - wipe the drive and re-install the original OS from the original disk set. The receiver of the machine can then decide which OS they want to upgrade it to, and purchse accordingly.
    The original disk set for that machine should be included with it when it is sold.

  • Time capsule intern.1TB hard drive.How can I delete all files

    Hello How can I delete all files from my timecapsule.
    I have connectet it with Wifi or ethernet. It is not possible.
    I have made a reset.
    I have tried it often.
    Please help
    Greetings from Vienna
    Pepimeier

    If you open Macintosh HD > Applications > Utiltiies > AirPort Utility and click Manual Setup, are you able to access the settings for the Time Capsule?
    Or, does AirPort Utility scan for the Time Capsule and then not find it?

  • Why won't preview let me delete all files (instead of all but one)

    In all OSX versions up to snow leopard in preview there was the option to select all open items and move the files to the trash. For some reason unknown to me, in 10.8.5 mountain lion that option no longer exists. Now preview lets me delete all files except one. If you have 2 images open you can move 1 to the trash. If you have 99 open you can move 98 to trash and if you have 1 open, you cannot move it to trash. Is there some code available where I can undo this restriction?

    Do you also have them on another computer, iPad or iPhone,  IF you do then it may be syncing them back

  • How can I create a array with all files from a directory

    How can I create a array of files or varchar with all files from a directory?

    I thought the example could be improved upon. I've posted a solution on my blog that doesn't require writing the directory list to a table. It simply returns it as a nested table of files as a SQL datatype. You can find it here:
    http://maclochlainn.wordpress.com/2008/06/05/how-you-can-read-an-external-directory-list-from-sql/

  • How to get the file size (in bytes) for all files in a directory?

    How to get the file size (in bytes) for all files in a directory?
    The following code does not work. isFile() does NOT recognize files as files but only as directories. Why?
    Furthermore the size is not retrieved correctly.
    How do I have to code it otherwise? Is there a way of not converting f-to-string-to-File again but iterate over all file objects instead?
    Thank you
    Peter
    java.io.File f = new java.io.File("D:/todo/");
    files = f.list();
    for (int i = 0; i < files.length; i++) {
    System.out.println("fn=" + files);
    if (new File(files[i]).isFile())
         System.out.println("file[" + i + "]=" + files[i] + " size=" + (new File(files[i])).length() ); }

    pstein wrote:
    ...The following code does not work. Work?! It does not even compile! Please consider posting code in the form of an SSCCE in future.
    Here is an SSCCE.
    import java.io.File;
    class ListFiles {
        public static void main(String[] args) {
            java.io.File f = new java.io.File("/media/disk");
            // provides only the file names, not the path/name!
            //String[] files = f.list();
            File[] files = f.listFiles();
            for (int i = 0; i < files.length; i++) {
                System.out.println("fn=" + files);
    if (files[i].isFile()) {
    System.out.println(
    "file[" +
    i +
    "]=" +
    files[i] +
    " size=" +
    (files[i]).length() );
    }Edit 1:
    Also, in future, when posting code, code snippets, HTML/XML or input/output, please use the code tags to retain the indentation and formatting.   To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.  It took me longer to clean up that code and turn it into an SSCCE, than it took to +solve the problem.+
    Edited by: AndrewThompson64 on Jul 21, 2009 8:47 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • List all files in a directory on a server that hosts the applet

    Hei :)
    I have a problem. I want to list all files in a directory on my server. ( http://www.foo.bar/tw )
    The applet is in the root folder ( http://www.foo.bar ).
    So i tried it like this
    File fi = new URL(getCodeBase() + "/all/").getFile();But when I try to list the files, I get a SecurityException.
    Can anyone help me out?
    Peace!
    LoCal

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blist+%2Bfile+%2Bserver

  • Finder not displaying all files in remote directory

    Sorry, this is a repost as I have gotten no response from my original request here: Finder not displaying all files in remote directory
    I've exported pictures from iPhoto on my iMac to a shared directory on my mac mini. When I access that directory from my iMac, I can see some but not all of the pictures. I know the pictures exported properly because I can see them all from the mac mini. I can open up a terminal window on my iMac and see all of the files; I can also open those files from the terminal.
    I'm running OSX 10.9.4 on both computers, with the mac mini also running OSX Server. I've placed a screen grab below from my iMac of what Finder sees vs what I can see from the terminal.
    Why isn't Finder displaying all of my files?

    thanks for responding
    Adding a new file to the shared folder results in me being able to see the new file from my clients regardless of where it was added from, however the "hidden" files do not suddenly pop up.
    I tried a few more experiments that had interesting results, but still didn't lead me to an answer.
    First I tried copying the files from the remote directory to a local directory; I did this in 2 different ways and had different results. Method A) I copied files from the mounted share to a local dir: "cp /Volumes/MyShare/dir/*.JPG .". Method B) I copied the files using secure copy: "scp user@server:/path/to/dir/*.JPG .".
    Method A resulted in Finder not being able to see the files in the local directory, while Method B did. This was interesting and lead me to suspect an issue with the way I am sharing the directory on the server. From Server settings I have both afp and smb checked. I tried enabling only one or the other and reconnecting; but this did not fix the problem.
    Next I tried exporting the photos from iPhoto again. Exporting them locally results in files that Finder can see. Exporting them to my server results the same bad behavior
    Getting desperate, I also tried renaming all of the files from "*.JPG" to "*.jpg" but this didn't help.
    One last experiment, I see the same behavior from both another Mac and a PC on my local network... FTP works fine.
    Any more ideas?

Maybe you are looking for

  • Upgrade to CS6 Design Standard problems

    I bought CS5 Design Standard on March 30, 2012 so I applied for the free upgrade to CS under the "Claim your complimentary CS6 Upgrade" program (http://helpx.adobe.com/x-productkb/policy-pricing/upgrade-policy-produ ct-announcement1.html).  I got an

  • Help needed in request.getParameter

    I have one table with field EMP_ID varchar(10) latin1_swedish_ci PRI I am passing the value of emp_id from one page to another.In the second page using request.getParameter i am receiving the value first page code: out.println("<td><a href = viewEmp.

  • HT201302 is my iphone phone pinpoint accurate when using find my iphone?

    how accurate is the location of the find my iphone app?. and sometimes when im looking for my lost iphone it shows  thel ittle green dot in different places everytime i refresh  in the   icloud website?

  • Local Web Development Using Spare Mac to View

    Hi Hum, hope I can be clear.... my mission: use old laptop (Tiger) to view web sites in the User/Sites folder on my new laptop (Snow Leopard) via web sharing. Why? Well, it's another screen, it's there and importantly, it represents the majority of v

  • Using Like function to search fr results in a database!!

    Hi i have created a database for several different clinics in the uk in oracle sql developer. i tried writing the coding for a query but when i run it an error keeps occurring. i want this query to be as a pop up box appears, asks the user to enter t