Deleting a directory and its content
Hi, I'm trying to delete a series of directories like this batch file does
@echo Removing "%CD%\a"
@rmdir /s /q "%CD%\a"
@echo Removing "%CD%\b"
@rmdir /s /q "%CD%\b"
@echo Removing "%CD%\c"
@rmdir /s /q "%CD%\c"looking at the api i found that it doesn't seem to have the option to delete a dir and its content, should i use a function like the one in thread:
http://forum.java.sun.com/thread.jsp?forum=31&thread=188034
or would it be better to call the batch script with Runtime.exec()? The system is windows only so i don''t need to have compatibility with *nix shells ect.
What do you think?
Try this
// CLASS: FileUtil
// FUNCTION: An extension of File which allows various file manipulations
import java.io.*;
import java.net.*;
import java.util.*;
public class FileUtil
extends File {
public FileUtil(File parent, String child) throws NullPointerException {
super(parent, child);
public FileUtil(String pathname) throws NullPointerException {
super(pathname);
public FileUtil(String parent, String child) throws NullPointerException {
super(parent, child);
public FileUtil(URI uri) throws IllegalArgumentException, NullPointerException {
super(uri);
public void deleteTree() throws Exception {
ArrayList contents = new ArrayList();
listContents(contents);
File f;
for (int i = contents.size() - 1; i >= 0; i--) {
f = new File( (String) contents.get(i));
f.delete();
private void listContents(ArrayList files) throws Exception {
listContents(files, this);
private void listContents(ArrayList files, File dir) throws Exception {
System.out.println(dir.getAbsolutePath());
File[] newFiles = dir.listFiles();
File newFile;
if (newFiles != null) {
for (int i = 0; i < newFiles.length; i++) {
newFile = new File(newFiles.getAbsolutePath());
files.add(newFiles[i].getAbsolutePath());
if (newFile.isDirectory()) {
listContents(files, newFile);
Similar Messages
-
Help me Friends - How to Delete a Folder and its contents in java
Hi Friends
I want to delete a folder and its contents by passing the folderpath.
Can any one help me in this..
Thanks in Advance
Regards
Krishna* Delete a directory including all of its content.
* @param directory Directory path to delete.
public static void deleteDirectory(String directory) {
if (directory != null) {
File file = new File(directory);
if (file.exists() && file.isDirectory()) {
//1. delete content of directory:
File[] files = file.listFiles();
int count = files.length;
for (int i = 0; i < count; i++) { //for each file:
File f = files;
if (f.isFile()) {
f.delete();
} else if (f.isDirectory()) {
deleteDirectory(f.getAbsolutePath());
}//next file
file.delete(); //finally delete (empty) input directory
}//else: input directory does not exist or is not a directory
}//else: no input value
}//deleteDirectory() -
Deleting directory and its contents recursively
File clearDir = new File(dirname);
String farr [] = clearDir.list();
for(int i = 0 ; i<farr.length; i++){
new File(farr).delete();
new File(dirname).delete();
above code only deletes directory files and directory.
say if the there are some other directories inside,how to handle it to delete them also??better version with stack implementation. (not a recursive function)
public void deleteDir(File dir){
Stack<File> dirStack = new Stack<File>();
dirStack.push(dir);
boolean containsSubFolder;
while(!dirStack.isEmpty()){
File currDir = dirStack.peek();
containsSubFolder = false;
String[] fileArray = currDir.list();
for(int i=0; i<fileArray.length; i++){
String fileName = currDir.getAbsolutePath() + File.separator + fileArray;
File file = new File(fileName);
if(file.isDirectory){
dirStack.push(file);
containsSubFolder = true;
}else{
file.delete(); //delete file
if(!containsSubFolder){
dirStack.pop(); //remove curr dir from stack
currDir.delete(); //delete curr dir -
How to append a file directory and its contents in a jTextArea
how will i display the contents of this file and file directory in a jTextArea or ...let's say it will display the content of "c:/AutoArchive2007-05-24.csv" in a jTextarea
say this file "c:/AutoArchive2007-05-24.csv"contains the ff:details
user:jeff AutoArchive-Process Started at Thu May 24 15:41:54 GMT+08:00 2007
and ended at Thu May 24 15:41:54 GMT+08:00 2007
Message was edited by:
ryshi1264use the append(...) to append data to the text area.
-
Powershell script for deleting sitecollection and its content db
want to know whether any powershell script is avlble for deleting the sitecollection and its content db at oneshot!
i have created sitecollection specific content db and i wanna delete the same.Hi,
Below link will help to delete site collection
http://technet.microsoft.com/en-us/library/cc262392(v=office.15).aspx
Thanks
Somnath Matere -
Mac OS 10.5 /
I deleted the " Private" folder ... and emptied the trash. So the folder and its contents no longer exists on my computer at all !!!
I do have the OS 10.5 dvd that i purchased years ago...
But my computer will not start from it on its own.
My question is what is the open source or terminal language code used to tell my mac to look in the DVD rom drive for startup info? I know that im not the only person in this world who has deleted the "PRIVATE" folder and emptied the trash so it no longer exists on their machine...
That said theres gotta be a common fix for a Power PC G4 that has the OS X dvd in the rom drive but wont look to it to reinstall the vital contents of the PRIVATE folder.
Once again there is not a copy of this file or its contents in the recycle bin...
Also rebooting the machine , pressing and holding the letter C does not prompt the machine to look to the dvd rom drive.
I was reinstalling pro tools and figured I would make some room by cleaning my computers HD...
Lol It was a bad choice to delete this file ...
Thanks guysOkay sorry it took forever to respond... But for a while there I gave up on this computer!!!!
Money's been tight lately , so taking it in to a professional was not yet an option... though I did consider it eventhough.
Anyway long story short im glad I didnt spend any money because I already had all the tools necessary to fix this issue but was going about it in the wrong way. Okay so here is my scenario and the breakdown... Though this may not fix the issue for everyone :( which *****... But I know we all will have different circumstances.
Anyway here we go...
Okay so first things first.... Years ago I purchased the OS 10.5.1 disk ... So that has always been in my possession!!!!
I realize that some may not have a disk to reflash your OS to your hard drive... but if you do your in luck.
2ndly ... I had an external harddrive with all of my itunes downloaded music so it was more than okay with me to delete my primary HD because all the important stuff could either be copied over or repathed to be located.
-------If you dont want to read through the whole story the fix is summed up in the bottom section-------
Okay so now the SOLUTION!!!!
By trial and error , and pure boredom I opened up my computer to clean the inside...
AND
"Disconnected the primary HD"
and just because ....... REBOOTED my computer. Just to see what it would do.
Upon restart and though it looked like it would repeat its usual cycle...
About 1 minute in to that process my computer froze for about 2 seconds and flashed to the OS installation screen.
Mind you I havent seen this screen yet... Probably hasnt been since I installed the OS years ago.
After a bit of trial and error...
I decided to tell my computer to startup from the OS 10.5 disk located in my dvd rom drive and restarted once again...
this setting is under
Utilities / startup disk
After a little more trial and error ... I realized that I could reconnect the primary HD , restart the machine and return to the OS installation menu.
So upon this discovery
I went to the Disk Utility located under Utilities
Highlighted my primary HD located in the left hand column
Once highlighted ...
In the heading section on the right I selected the option
Erase
in which I erased My current OS on my primary HD ...
I used the first option in the list under security... Because it seemed like the least invasive and would take the least amount of time to see if this process would actually work.
I FORGOT to add something...
Another reason why I deleted my primary HD!!!!!
I forgot to say that it WOULD NOT!!!!! Show up in the STARTUP list as an option...Even After multiple reboots....
But like clockwork... Once I deleted its name IT SHOWED UP as an option!!!!
So back to the next step...
I returned to the STARTUP option under utilities ... And was then able to see MY primary HD now as a startup option...
But ofcourse it had no name because it we previously erased it.
So when Clicking my newly erased HD ... I was almost immediately prompted to REINSTALL the OS ...
Which said it would take about 57 minutes ... But I believe was alot less...
My issue was resolved ... My computer then stated the install was SUCCESSFUL!!!!!!! :))))))))))) lol ;)
It was like I was setting up for the first time ;) asking for my registration info...
The dilemma of deleting the private folder and emptying the trash is finally over resolved. Done ... and no extra money spent!!!!!!!!!
Its really crazy that the information for such a simple thing is not readily available. Especially being such a simple fix.
I know im not the only person who's had this issue , because i've seen numerous posts with similar wording.
I also know I wont be the last person to have this issue... So I hope this synopsis makes sense.
-------One more time the fix------
*Insert your OS dvd into your dvd rom drive.
*Unplug your primary HD or corrupted startup disk
*Reboot your machine...
Upon restart your primary HD will not be recognized...
* you will then be prompted to select your language.
Once selected
*Click Utilities/startup... Highlight the the selection that refers to the OS dvd located in the dvd rom drive.
* Click restart...
!!!!!!!!!!Be sure to reconnect your Primary HD Before your computer restarts and you hear the chime!!!!!!!!
If you do not replug your HD before the chime it will not be recognized.
In that case restart again.
Upon restart once again
*Choose your language...
*Click Utilities / disk utility
In the left column select and
*Highlight your HD ...
Then towards the top portion / center of the page
*Click the heading Erase
Then on the page toward the bottom
*Click security options
This will then provide erase options.
I USED THE FIRST OPTION
"Dont erase data"...
*click OK
* click erase...
Once erased which should take a few seconds
*Cancel the disk utility...
* Click Utilities / startup
And your newly erased HD should now appear in the list.
* Select your drive from the list by highlighting
It should no longer have a name.
*Once selected, you will then be prompted to restart and install the OS to your newly erased HD...
Thats it!!!!
Once everything reinstalls re-add your personal info or registration info and you are up and running.
Goodluck ;) -
Is it possible to recover a deleted folder and its contents as opposed to an individual file?
When I turned on my computer today, a folder located on my desktop is no longer there. Astounded I could have accidentally deleted it, the folder having been trashed is the only illogical logical possibility I can think of - and is a first for me in my 30 years of Mac use. My father is in the process of dying and the folder contains all the information coming to me on the subject. The last backup of this folder is about a week old and much has been added since for which I've no record.
Not having a master document or table of contents listing what was in the folder leaving me unable to search for and recover individual files/documents by name, my question is this: Is it possible to recover a "FOLDER", and its contents after that folder has been moved from the desktop to the trash, the trash emptied, and the computer having been shut down?
If anyone has any ideas of how to recover anything about what items that folder contained, I'd really appreciate whatever thoughts you might have.
Thanks in advance -
The computer this folder is missing from is a early 2008 MacPro, running 10.7.5.I'm not sure what you can do beyond trying to restrict the types of files you search for. These apps normally have ways to select the file types or to add example files. That allows them to carve out only those types, but you still may end up with GB's of data, especially if the types are somewhat generic. I don't know of any tools that can undo changes to the disk catalog over time.
I guess you could also search for specific text if you know that these files contained something that is 'almost unique'. Spotlight can do that, or grep, egrep are command line tools that may help ask if you want to go that route, they may help you gather lists to move files around to whittle them down.
Sorry I can't think of a way around this it's a difficult task at a difficult time. Good luck with it, ask if you think we could help.
I do wonder if Apples 'Versions' could help?
OS X Lion: About Auto Save and Versions - Apple Support
@Tony T1, do you know how to restore files from that system? I think it is part of Time Machine, but the copies are saved locally.
It is not entirely clear how it works (at least from my memory of Lion) with regards to how you could get files back in this situation. The database should be at the base of the disk in a hidden folder ".DocumentRevisions-V100", but I don't think you can just pull files out of there. Personally I'd consider making a full disk backup before you attempt to restore files. Then you could try the 'Enter Time Machine' UI to see if it can browse back to the older Desktop. -
soem how my iphone deleted an app. can I retore it and its contents? How? thanks
Redownload it from the app store.
-
HT201301 How do I import a garageband project folder (and its contents) into itunes?
How do I import a garageband project folder (and its contents) into itunes so I can transfer it to my ipad?
I am a guitar teacher and I want to use garageband for the ipad as a teaching tool for my students. The goal is for my students and myself to share garageband project files so that both the teacher and the student can have the full project...or even add to it.
Here's what I need help with...
My student has created a song in garageband that has 4 tracks. They sync their song to itunes so they can see the project folder for that song in the document window for garageband under the "apps" tab in itunes. They click "save to" and save the project folder to dropbox.
I want to be able to import the project folder for that song from dropbox into itunes so that I can copy it to my ipad and have full access to my student's song.
I appreciate any help! Thanks!
Pat
[email protected]hi Pat,
what you can do is add that folder to garageband directory using ifunbox. here is the step:
- Open your ifunbox then go to "user Applications" on your left panel, then select garageband folder. You will see a folder as below:-
"Documents"
"Library"
"MobileGarageBand.app"
"tmp"
"itunesartwork"
"itunesmetada.plist"
copy the folder you like to put into your ipad by copy it into "Documents" folder. and then quit the ifunbox and restart your itunes again and sync your ipad again and check if you can see the folder on your file sharing under apps tab. Wish you good luck. -
How to create new .dat file and its contents?
Hi There
Can anybody let me know the procedure of how to create new .ctl or .dat file to load data to tables.
i working on 2day dba chapter 8. it shows me how to creat table and use .dat file to load data. but doesnot giv any clue how new .dat file and its contents can be created. please help.
thanks in advance.Thanks for ur help
I ve created txt file in notepad and saved it as dat file. tried to load that data thru Enterprise manager. used load data from User files everything went well and job was showing suceeded but dont know why that data is not showing in the table. i ve tried it now for three four times. used right table and pathe but dont know. has anybody got idea why that ll be?
Thanks -
PSE9: How do I move/copy an Album and its contents from my PC to my laptop?
I am using Windows 7 and PSE 9 on my PC and want to get a copy of the album and its contents to my Vista laptop running PSE 9 without changing anything on the source PC. Anyone know how to do this? I know I can move the files through Windows Explorer on my network but I have already gone through the trouble of putting the best photos into an Album and would like to simply move the Album over and not have to go through the trouble of recreating it.
You will need to copy the files.
1. Make a new folder on your laptop
2. Open Organizer, select your Album then press Ctrl+A to select all photos
3. Click the Fix tab and choose Full Photo Edit to open the album contents in the editor
4. Click File >>Process Multiple Files
5. From the drop down menu (Process files From) choose Opened Files
6. For destination click the browse button and navigate to your new folder on your network and click OK
7. Make sure Rename and Resize is unchecked but check Convert files To and choose Jpeg Max quality or whatever you prefer then click OK and wait for Elements to finish.
8. Go to your laptop folder to see your images. -
To set a directory and its subdirectory in utl_file_dir using command
Hi all ,
Please help me in this dbt .
in one article i saw
UTL_FILE_DIR lets you specify one or more directories that Oracle should use for PL/SQL file I/O. If you are specifying multiple directories, you must repeat the UTL_FILE_DIR parameter for each directory
on separate lines of the initialization parameter file
and in another alter system set utl_file_dir=dir1,dir2 scope=both;
whther the second method is possible
if i want to have a directory and its sub directory to set in utl_file_dir
what i should do , whether i want to specify main directory and all sub directory seperated by comma or any other method is there
Please help me
thanks in advance ..........Instead of specifying the directory in the INIT.ora file u can use Directory object.
U need to create a directory object once & use it when ever u require it.
For example
CREATE OR REPLACE DIRECTORY Test_dir AS 'C:\abc'
Now you can use this directoryTEST_DIR in any Pl Sql block provided u have proper privileges. -
How to move some xml element and its content to a new frame
Hi All,
How to move some xml element and its content to a new frame.Hi Chinnadk,
Sorry my code its comment some lines. Now only I check the forum thread, you just try one more time.
#target InDesign;
#include "/Program Files (x86)/Adobe/Adobe InDesign CS5.5/Scripts/XML Rules/glue code.jsx"
var myDoc = app.activeDocument;
//____________________ XML RULE SET
var myRuleSet = new Array (new margintag);
with(myDoc){
var elements = xmlElements;
__processRuleSet(elements.item(0), myRuleSet);
function margintag(){
this.name = "margintag";
//this.xpath = "//margintag[@type='mn2']";
this.xpath = "//margintag";
this.apply = function(myElement, myRuleProcessor){
with(myElement){
app.select(myElement);
try{
var myPrePara = app.selection[0].paragraphs[-1].parentTextFrames[0].paragraphs.previousItem(app.selection[0].paragraphs[-1]);
if(myPrePara.characters[-1].contents=="\r"){
myPrePara.characters[-1].remove();
var myTextframe = myElement.placeIntoInlineFrame(["7p9","6p"]);
myTextframe.appliedObjectStyle= myDoc.objectStyles.item("MN1");
myTextframe.fit(FitOptions.FRAME_TO_CONTENT);
myTextframe.parentStory.paragraphs.everyItem().appliedParagraphStyle = app.activeDocument.paragraphStyles.itemByName("MN1");
}catch(e){}
app.selection = null;
return true;
thx,
csm_phil -
Is it possible to sign the transport and its content?
Hey Everyone,
Is it possible to sign the transport and its content when I release transport? So that when a particular transport is imported into destination system we can say with certainty that transport is not tempered with?
I am more worried when we give data and cofile to be imported into some System it may be tempered with so that it may look like the same transport but its contents are modified. (I am not sure even if its possible for somone to modify these files and hence the actual ABAP Object in it are changed.)
Of course, it is possible to sign the file content itself and send it over, but I am trying to minimize the risk even more so that when we release transport or when someone is importing it signing is automatically done or checked.
Thanks,
NilayThere is no way of sense water and CO2 by a single sensor.You could be able to measure CO2 and water seperately but before that i need to know much details and chemical specifications about your liquid.
-
Update integration directory and repository content after PI system copy
We are on PI 7.1, We are trying to figure out the best way to update the contents in sld, integration directory and repository after system copy. currently we delete everything in sld, ID and IR then reimport all the content to get everything in-sync. Is there an easier way to do it, ex. just update the system in sld and the matching contents in IB and IR?
Thanks,
Jane ZhouHi Jane
This completely depends on the nature of the system copy and your SLD architecture and operational requirements
Will the source system remain available or operational ?
Is the target SLD proposing to use satellite systems already defined in the source SLD ?
When doing a system copy the following should be considered
1) If you create an import line from a previous SLD via export or sync
- that SLD has to continue to be available for further updates or sync
2) If you create a system copy, any target specific configuration like hostname, port, SID
may needed to be adapted in target landscape
3) Further considerations are needed if 1 satellite will point to 2 SLDs at the same time both for operational use
Its very easy to take a back-up or full or partial import from one SLD and put it into another or indeed sync between SLDs
however the key is to ensure the target SLD content is consistent and useable in the same way as the source SLD
Hope this helps
Stuart
Maybe you are looking for
-
Hi Strange problem I have had my new iPad mini since spring. I have had no issues watching movies from I tunes and last evening it keeps telling me there is no storage space to download I have removed apps turned things off including iCloud and still
-
IDvd 5 problem on Intel Macbook!
I am having problems running iDVD 5 on Intel Macbooks. iDVD 5 loads up, the themes show up in the side tray and the music plays. However, the themed "images and drop zones" are not visible in the main window.... in its place, only a black background
-
My acct is in spainsh how do i get it to english
changing from Spanish to English on my acct
-
If I've only one R/3 backend system, can I still define it in a logical sytem in RAR? Thank you, Partha
-
Credit Score in the 400's and I'm feeling awful :(
I went from a 700 credit score to now 490 and I'm not sure how or where to begin towards repairing my credit. I separated from my husband 2 years ago because our relationship was becoming extremely dysfunctional and I didn't want to expose my 2 year