How to know a priori if a file can be deleted?

My application requires that a collection of files be deleted. I currently loop through an array of File objects to be deleted, and invoke the delete() method on each object, i.e.
for (int i=0; i<collection_of_files.length; i++) {
returnval = collections_of_files.delete();
Problem: If one or more of the files has a "lock" on it, such as in Windows when some other process may be accessing the file, then those files can not be deleted, and returnval = false. How could I know before deleting ~any~ files in the collection, if some of the files can not be deleted? I would prefer not to actually delete any of the files in the collection, if one or more files can not be deleted because of a lock or any other reason. I have tried using SecurityManager to perform this a priori check on the deletability of a file, but no luck! Please advise.
thanks,
Ed

It tries to delete a temp file that doesn't exist, so
it doesn't delete anything in fact.Yes, the statement tempFile.delete() is not actually needed in the function isFileInUse. Other than that, the function isFileInUse does serve its purpose -- it determines true or false if there is a lock on a file. It does so by trying to rename the source file. If it can rename the source file, then we know there is no external lock on that file, and the function renames it back to what it was and returns false. This is a little tricky, but it works great. However, you would think there is a better way.
It was suggested also to try using the java.nio.filechannels.FileChannel class, which may be the proper way to go, but I haven't tried it yet. In particular, the method FileChannel.tryLock() returns "null if the lock could not be acquired because another program holds an overlapping lock."

Similar Messages

  • I have one file ss_fpga.rbt,abcd.txt how to know the details of the file

    i have  one file  ss_fpga.rbt,abcd.txt how to know  the details  of the file  (when was the date created ,when was date modfied,owner) any function is there like   GetFileInfo

    Yes there is some, called stat(), look the links in your post in stack overflow, there is a lot of link in the anser.
    They talk about sys/stat.h a C header, witch contain the stat() function.
    stat() return a lot of things (size, changes, access etc) about files. look the "here" everywhere in the Yann anser, UP his anser and put the subject as resolved.
    Thanks,

  • How to know if my HP Pavilion Notebook can support Super Multi Blue-Ray drive?

    Hi,
    My HP laptop is:
    HP Pavilion dv6-6093ex Entertainment Notebook PC support
    LM610EA#A2N
    How to know if my HP Pavilion Notebook can support Blue-Ray drive?.
    I need to install a Super Multi Blue-Ray drive, with these capabilites::: read and write all types of disc formats in one convenient package: CD±R, DVD ±R ,  CD±RW, DVD±RW, CD-ROM, DVD-ROM, DVD-RAM and Blu-ray disc.
    If it can support, then I must purchase HP Blue-ray device, or I can purchase any other brands, such as  LG 16x Internal Blu Ray/DVD/CD Burner Writer Drive + sata data & power cables .
    First of all: my Optical drive is: LightScribe SuperMulti DVD±R/RW with Double Layer Support, and with the capabilities
    hp CDDVDW TS-L633R
    Media Type DVD Writer
    Name hp CDDVDW TS-L633R
    Availability Running/Full Power
    Capabilities Random Access, Supports Writing, Supports Removable Media
    Read capabilities CD-R, CD-RW, CD-ROM, DVD-RAM, DVD-ROM, DVD-R, DVD-RW, DVD+R, DVD+RW, DVD-R DL, DVD-RW DL, DVD+R DL
    Write capabilities CD-R, CD-RW, DVD-RAM, DVD-R, DVD-RW, DVD+R, DVD+RW, DVD-R DL, DVD+R DL
    Config Manager Error Code Device is working properly
    Config Manager User Config FALSE
    Drive E:
    Media Loaded FALSE
    SCSI Bus 0
    SCSI Logical Unit 0
    SCSI Port 0
    SCSI Target Id 1
    Status OK

    Anyway, Could you please confirm for me this the Maximum resolution of my VGA is 1366 by 768 pixels, and cannot be extended.
    That is correct.  It cannot be extended.  That is the limit for the built-in display.  Using an external display that is capable of higher resolution might help in that matter but then you loose the portability of the laptop.
    I came across a free BluRay player just this week, it is found here. Leawo Blu-ray player: http://www.leawo.org/blu-ray-player/
     It is the only free BluRay player I have found.
    That is about all I can do to help.  The other possibility would be to get an external Bluray drive that can fulfill all your  expectations, give you lightscribe, and possibly a BluRay player included with the purchase.  It would be much less worrisome on your part and there would not be any modifications to the laptop.
    {---------- Please click the "Thumbs Up" to say thanks for helping.
    Please click "Accept As Solution" if my help has solved your problem. ----------}
    This is a user supported forum. I am a volunteer and I do not work for HP.

  • What files can i delete to make more room on my startup disk

    what files can i delete to make more room on my startup disk

    Maybe some help here
    http://support.apple.com/kb/HT3680
    Also delete your cookies and other web data, as it can build up and you don't really need that stuff.
    Try going to to Go in the finder menu, Go to Folder, Type in ~/Library/ click Go and look around and see what you don't need and highlight and delete the junk.

  • If I convert a PDF file to a Microsoft Word file can I delete pictures from the converted file

    If I convert  PDF file to a Microsoft Word file can I delete pictures from the converted file?

    Hi sutterrot,
    After a successful conversion from PDF to Word, you need to download the converted file locally on your computer.
    You can then choose 'Enable Editing' button and then delete images/text or make other changes.
    Regards,
    Anubha

  • How to know a line of text file is ending with line feed or return?

    hi all, i have a program that read log file that generated by other service (apache http server for example), i want to know that each line is ending with "\r", "\n" or "\r\n" so i can skip them in the next time, like this:
    int char_counter=0;
    BufferedReader reader = new BufferedReader(new FileReader(logFileName));
    while((line=reader.readLine())!=null){
           char_counter+=line.length()+x_value;
    }and the next time read the log file, i will skip all the lines that read in previous time.
    BufferedReader reader = new BufferedReader(new FileReader(logFileName));
    reader.skip(char_counter);
    while((line=reader.readLine())!=null){
           char_counter+=line.length()+x_value;
    }with x_value is 1 or 2 depended on line end with "\n" or "\r\n".
    so, how to know which is the char line ending with?
    Edited by: secmask on Feb 21, 2009 5:46 AM

    Alright, the BufferedReader method readLine() reads all text until it finds a \n character. And then next time you call it it will automatically continue from where it left out.
    try this out it should show it as an example
    import java.io.*;
    public class readLineTest {
        static FileOutputStream filename;
        static BufferedReader input;
        public static void main(String[] args)
            try
                filename = new FileOutputStream("logFile.txt", false);
            catch (IOException e)
                //blank
            PrintStream output = new PrintStream(filename);
            output.println("this is the first line");
            output.println("this is the second line");
            output.println("this is the third line");
            try
                input = new BufferedReader(new FileReader("logFile.txt"));
            catch(IOException e)
                //blank
            for(int i = 0; i < 3; i++)
                try
                    System.out.println(input.readLine());
                catch(IOException e)
                    //blank
    }

  • How to know the size of a file in a program ?

    I am compiling a program and I have to use a function in Java to know the size of some files. How can I do? Thanks

    File.length() not good enough?

  • How to know if a sent-email was opened or deleted? AnyThing in API??????

    Hi pal,
    Is there anyThing in API to know if a sent email has been opened or deleted by reciever?
    Asif

    Hi,
    Even i am having a similar problem..
    I want to track the emails sent out from my application.
    Whether the mails are read or not and if read for how long they are read???
    Can anyone give me an idea abt this.
    Thank u

  • File Adapter found error,source file can't delete

    I have configured scenario File to File, the target file is also created,but can't delete source file
    I checked the path of source file,it's correct.

    Hi,
    Please check
    1) whether you have sufficient permissions on the folder to delete the file.
    2) Also check the Processing mode parameter
    Regards,
    Edited by: Vijaya Lakshmi MV on Sep 5, 2008 5:22 PM

  • Kernel_task using too much RAM, which .kext files can i delete?

    Please find the list of the .kext files below. Which ones can I delete?
    file:///Library/Extensions/ArcMSR.kext/
    file:///Library/Extensions/ATTOCelerityFC8.kext/
    file:///Library/Extensions/ATTOExpressSASHBA2.kext/
    file:///Library/Extensions/ATTOExpressSASRAID2.kext/
    file:///Library/Extensions/CalDigitHDProDrv.kext/
    file:///Library/Extensions/HighPointIOP.kext/
    file:///Library/Extensions/HighPointRR.kext/
    file:///Library/Extensions/PromiseSTEX.kext/
    file:///Library/Extensions/SoftRAID.kext/
    Thanks!

    Please find the list of the .kext files below. Which ones can I delete?
    file:///Library/Extensions/ArcMSR.kext/
    file:///Library/Extensions/ATTOCelerityFC8.kext/
    file:///Library/Extensions/ATTOExpressSASHBA2.kext/
    file:///Library/Extensions/ATTOExpressSASRAID2.kext/
    file:///Library/Extensions/CalDigitHDProDrv.kext/
    file:///Library/Extensions/HighPointIOP.kext/
    file:///Library/Extensions/HighPointRR.kext/
    file:///Library/Extensions/PromiseSTEX.kext/
    file:///Library/Extensions/SoftRAID.kext/
    Thanks!

  • I don't know my restrictions passcode, and i can't delete any of my apps. Suggestions please?

    Hi, I'm having trouble with my apps, I can move them around but I can't delete them! I can't remember my restrictions passcode which means I can't change the settings so that I can delete my apps that I don't want anymore. Any suggestions how I can find out my restriction code would be greatly appreciated.Thanks a mill  

    Ya I cant either and i forget my restriction passcode please someone help us:)

  • No space.  Two sparsebundle files--can I delete one?

    There are two Macbooks backing up a Time Capsule on our wireless network.  My mother noticed an error message on her laptop saying there's not enough space for Time Machine to perform a back up.  I took a look at the Time Capsule, and sure enough, there's only 8 gigs left, even though in theory there should be plenty of space.  (By my estimation maybe 100 gigs or so.)
    I scanned my Time Capsule with GrandPerspective and noticed that my laptop has two sparsebundle files on the Time Capsule.  One hasn't been updated since March.  The only thing I can think of is that In the Spring I changed settings in Time Machine to back up a folder I hadn't backed up before.  The other sparsebundle file is current to today.
    Can I somehow get rid of the older one without causing too much trouble?
    Thank you!

    If you don't plan to access any of the data on the older "sparsebundle" file, I'd delete it.  That will probably take a few minutes.

  • How to know the extension of the file stored in BLOB

    Hi Frens
    I've a BLOB column in which signatures are stored.Now i am extracting the signatures which are stored in the server.The extension of the file is .bmp as I'm appending it while extracting the file.Is there a way to know what is the file format or extension of the file which is stored in the BLOB coz I facing some problems with it.I just want to export the file with the same extension with which it was inserted in like .gif or .jpg.
    If u people know any resolution to this problem,please lemme know...It will be a great help
    With Regards
    Mohit

    As Billy said, the passing through correct mime type is the only reliable way. If you have already loaded tons of blobs without providing this information, you may try a small workaround to determine the right mime type for your files by emulating the file utility behaviour in the database - you have to load the /etc/mime-magic or something similar for your os into the database and then compare certain bytes of your lobs with those recorded in the mime-magic file. An example how it can be done is here
    http://articles.techrepublic.com.com/5100-9592_11-5219073.html
    You could so complete the missing information in the database without to unload your data , but you should be aware - this can not replace the need to provide right mime type information by loading into database.
    Best regards
    Maxim

  • How to know the size of the file

    hi all ,
    how can I know the file Size (like 23K, 45K, 0K)..
    if anyone knows please help me
    thanks

    Just use the length of the File class...

  • How to know dimension of a swf file

    I need to put up some swf file to the web site. The swf files
    are downloaded from our provider's site. We didn't got any Flash
    tools. I know the swf could be resize, but I want the swf just fit
    in a <table>. Therefore, I need to know the original
    dimension or the aspect ratio of the swf files.
    Does the free flash player got any help? Or any freeware
    could do the same thing? Could native Active Server Page (ASP)
    detect the ratiio?
    Thank you.

    If you're using AIR, I believe you can use the
    FileSystemDataGrid control (see
    http://livedocs.adobe.com/labs/flex/3/langref/mx/controls/FileSystemDataGrid.html)
    Peter

Maybe you are looking for