Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

Reading Sub Directories (Random) and deleting its contents?

Thread view: 
gaur.ritesh@gmail.com - 02 Mar 2008 15:44 GMT
Hi,

I am looking for a code to read sub directories that are created
randomly by "another program".i.e the name of the directories are not
known in advance.

For Example:

Root Dir is "Systems01"
Under "Systems01" they are many Directories (created by a program
randomly)

For example"

Systems01
------alpha
------qwerty
------ggrt
------remake

Next time I will start my computer these sub directories will be
different (alpha,qwerty....), so I need to make a generalize program
to delete these directories as well as contents.

Please note: "Another program" is not a virus, its a java program :)
Arne Vajhøj - 02 Mar 2008 16:37 GMT
> I am looking for a code to read sub directories that are created
> randomly by "another program".i.e the name of the directories are not
> known in advance.

The File class has methods to find all subdirectories in a given directory.

Arne
RG - 02 Mar 2008 17:15 GMT
> gaur.rit...@gmail.com wrote:
> > I am looking for a code to read sub directories that are created
[quoted text clipped - 4 lines]
>
> Arne

YA! Thats True, but I also need to delete the contents inside them.

Sample Code .......

------------------------
File f1 = new File ( "C:\\Systems01") ;

File[] strFilesDirs = f1.listFiles ( );

for ( int i = 0 ; i < strFilesDirs.length ; i ++ ) {
if ( strFilesDirs[i].isDirectory ( ) )
System.out.println ( "Directory: " + strFilesDirs[i] ) ;

else if ( strFilesDirs[i].isFile ( ) )
System.out.println ( "File: " + strFilesDirs[i] + " (" +
strFilesDirs[i].length ( ) + ")" ) ;

-------------------------------------------------
This is what I am using, the problem is to delete the particular
content from a sub directory.
Such As:

Systems01
---Alpha
-----Kilo
-------Temp

I need to delete the contents of the Temp Directory!

Alpha is a random name, but the inside structure is going to be same
(Kilo>Temp)
Christian - 02 Mar 2008 17:21 GMT
How about writting a method that recursivele deletes everything ..

maybe recursion would do the job?

Christian
Robert Klemme - 02 Mar 2008 17:45 GMT
>> gaur.rit...@gmail.com wrote:
>>> I am looking for a code to read sub directories that are created
[quoted text clipped - 35 lines]
> Alpha is a random name, but the inside structure is going to be same
> (Kilo>Temp)

Does it need to be a Java program?  I'm asking because usually this can
be easily done by standard tools available on your operating system
("del" on windows or "rm -rf", "find ... | xargs rm" on Unixes).

Kind regards

    robert
petersprc - 02 Mar 2008 19:10 GMT
Hi,

Here's the code:

http://www.rgagnon.com/javadetails/java-0483.html

Probably better than using Runtime.exec which would be less
portable...

> >> gaur.rit...@gmail.com wrote:
> >>> I am looking for a code to read sub directories that are created
[quoted text clipped - 43 lines]
>
>         robert
Roedy Green - 03 Mar 2008 21:07 GMT
>YA! Thats True, but I also need to delete the contents inside them.

you mean wipe the file for security?  When you delete the file the
sectors it occupies are put on the free space chain to be reused.
normally that is sufficient.

The CIA can recover data even if you wipe several times. See
http://mindprod.com/jgloss/wipe.html
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Arne Vajhøj - 17 Mar 2008 03:54 GMT
>> gaur.rit...@gmail.com wrote:
>>> I am looking for a code to read sub directories that are created
[quoted text clipped - 33 lines]
> Alpha is a random name, but the inside structure is going to be same
> (Kilo>Temp)

You can recurse through multiple levels of directories.

If you have an "order of delete" problem, then put the
to be deleted stuff in a collection in the correct order
and delete from that in the end.

Arne
Roedy Green - 03 Mar 2008 07:14 GMT
>Next time I will start my computer these sub directories will be
>different (alpha,qwerty....), so I need to make a generalize program
>to delete these directories as well as contents.

for code to do it, see http://mindprod.com/products1.html#BATIK
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.