2 Replies - 825 Views - Last Post: 28 February 2007 - 02:11 PM Rate Topic: -----

#1 Ryan Smith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 14-February 07

Limited File Transversal

Posted 28 February 2007 - 10:01 AM

For a disk database program I'm working on my conspirators and I have deemed it worthy to add in a method that will recursively go through a CD's directory and copy all file and directory names.

This seems like a good idea because the CD directory trees are not expected to be more than 100 or so items in maybe 2 or 3 levels. But because this is being developed on a computer where the program will be tested but not used, the directory roots will change.

Here is the simple algorithm for transversal:

public void hitAllFilesAndDirectories(File dir) {
		
		//here is where I will be logging the file/directory name and creation date.
	
		if (dir.isDirectory()) {
			String[] children = dir.list();
			for (int i=0; i<children.length; i++) {
				hitAllFilesAndDirectories(new File(dir, children[i]));
			}
		}
	}



I was thinking of using the JFileChooser to allow the user to select the CD... But that allows an enormous possible user error because of the recursion.

So my question is this:

How can I ensure that this will be used only on Disk devices (CD/DVD...)? I don't want the user to be able to do this method on the hard drive, generating some enormous response file. I cannot put a cap on the length or number of items, but I can't allow an overflow because of a user error.
Is there a way I can make sure the user has not selected the same root directory that the classpath is on? Or can I actually determine if it is an (allowable CD) disk?

Is This A Good Question/Topic? 0
  • +

Replies To: Limited File Transversal

#2 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Limited File Transversal

Posted 28 February 2007 - 12:15 PM

Looking at the File API provided me with the following idea

	for ( File root : File.listRoots() ) {
	  if ( !root.canWrite() ) {
		// do something
	  }
	}



OK, this is probably not the best way to go about it, but for the most part, CD drives are non-writable. There must be a more robust way of determining which root is the one with a CD in it, but I only had a few minutes. Is this going to be a CD that you created in the drive? If so, you can put a file in the root of the CD directory that identifies it as such. Otherwise, I'm not sure what else you can do at the moment.
Was This Post Helpful? 0
  • +
  • -

#3 Ryan Smith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 14-February 07

Re: Limited File Transversal

Posted 28 February 2007 - 02:11 PM

I'll sure try to implement that... it should work.

To answer your question:
These disks are data DVDs with 30-40 files/dirs on each. Already created.
I just want a simple way for the user to select which drive is their disk drive, and then pull off all the file names for searchable storage.
I just dont want the user to be able to generate a file list from the hard disk.

Thanks much, I'm off to try that now.

This post has been edited by Ryan Smith: 28 February 2007 - 02:13 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1