Getting list of files in root directory
I have seen many forum talking somewhat on this subject but I always see them using c: (for windows) as the example directory. I need to write this so that I can go to a Unix directory.
Example:
I want to go to the root directory from where I am....I would use runtime.exec(), right? But does the runtime actually go to that directory or just run the exec?
If there was a "name" such as c: in unix like windows it would be easier. But, I can not just say the name of the directory is / to get in there and check out the files. So, really what I want to do is if someone is not in the particular directory I want to be able to go to the root directory and check files there, then go to another directory and check the files there, etc.
I have a hard time explaining things so hopefully someone will get me.
Thanks.
But the trouble I am running in to is that I want the
root directory in Unix, which would be /. I can not
not just put that as the directory, can i?You can if you spell it out:
/export/home/thefunnyrootename
... or use:
String sysprop = System.getProperty("whatever property");
File f = new File(sysprop);... To determine which you want, SDK v1.3.1 docs for System.getProperty():
getProperties
public static Properties getProperties()
Determines the current system properties.
First, if there is a security manager, its checkPropertiesAccess
method is called with no arguments. This may result in a security
exception.
The current set of system properties for use by the
getProperty(String) method is returned as a Properties object.
If there is no current set of system properties, a set of system
properties is first created and initialized. This set of system
properties always includes values for the following keys:
Key Description of Associated Value
java.version Java Runtime Environment version
java.vendor Java Runtime Environment vendor
java.vendor.url Java vendor URL
java.home Java installation directory
java.vm.specification.version Java Virtual Machine specification version
java.vm.specification.vendor Java Virtual Machine specification vendor
java.vm.specification.name Java Virtual Machine specification name
java.vm.version Java Virtual Machine implementation version
java.vm.vendor Java Virtual Machine implementation vendor
java.vm.name Java Virtual Machine implementation name
java.specification.version Java Runtime Environment specification version
java.specification.vendor Java Runtime Environment specification vendor
java.specification.name Java Runtime Environment specification name
java.class.version Java class format version number
java.class.path Java class path
java.ext.dirs Path of extension directory or directories
os.name Operating system name
os.arch Operating system architecture
os.version Operating system version
file.separator File separator ("/" on UNIX)
path.separator Path separator (":" on UNIX)
line.separator Line separator ("\n" on UNIX)
user.name User's account name
user.home User's home directory
user.dir User's current working directory
Note that even if the security manager does not permit the getProperties
operation, it may choose to permit the getProperty(String) operation.
Returns:
the system propertiesThrows:
SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access to the system
properties.See Also:
setProperties(java.util.Properties), SecurityException,
SecurityManager.checkPropertiesAccess(), Properties~Bill
Similar Messages
-
Get list of files in a directory
Hello everybody,
working with Oracle 9.2 I have created a directory and i would like to implement in pl/sql a procedure that return the list of files contained.
Anybody know the general solution for this matter?
Thanks in advanceTom Kyte has an example:
Directory List including modify date and times -
Getting list of files from Unix directory inclding files frm sub-directries
Hi All,
I am trying to use Fm 'SUBST_GET_FILE_LIST' and
'RZL_READ_DIR_LOCAL' for getting a list of all files in a Unix directory including files from sub-directories.
In the first case I am getting an Exception called 'Access Error'
and when I use the 2nd FM, I am not getting any output.
Is there a special way to use these FMs.
Kindly help.
Regds,
Shweta[url http://java.sun.com/developer/JDCTechTips/2003/tt0122.html#1]READING FILES FROM JAVA ARCHIVES (JARS)
-
How to get list of file names from a directory?
How to get list of file names from a directory?
Please helpIn addition, this:
String filename = files;Should be this:
String filename = files;
That's just because he didn't use the "code" tags, so [ i ] made everything following it become italicized. -
Getting the list of files in a directory by their last modified date
Dear friends,
I want to get the list of files in a directory sorted by their last modified date.
By default the file.list() or listFiles() return files sorted by their name in ascending order.
Please give me your suggestions.
Thanks in advance,
James.Thanks friend,
I myself got the answer
here is my code:
public File[] getSortedFileList(File dir){
File[] originalList = dir.listFiles();
int numberOfFiles = originalList.length;
File[] sortedList = new File[numberOfFiles];
long[] lastModified = new long[numberOfFiles];
for(int i = 0; i < numberOfFiles; i++){
lastModified[i] = originalList.lastModified();
Arrays.sort(lastModified);
for(int i = 0; i < numberOfFiles; i++){
for(int k = 0; k < numberOfFiles; k++){
if(originalList[k].lastModified() == lastModified[i])
sortedList[i] = originalList[k];
System.out.println("The sorted file list is:" + sortedList[i]);
return sortedList; -
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!
LoCalhttp://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blist+%2Bfile+%2Bserver
-
Is there a way that you can get a list of files in a directory that are spelt a certain way? Ex. If in a directory there are html files, txt files, et, In java can I get *.html or a html file with certain text in the name? java.html??
How you can Help
US101here are the code to list your files
File startDir = new File("your directory goes here" );
File[] dirList = startDir.listFiles();
if (startDir.isDirectory());
out.print( startDir.getPath() );
//Start cycling through the array for the file
for ( int count = 0; count < dirList.length; count++ )
String fileName = dirList[count].getName();
int index = fileName.lastIndexOf('.');
String newString = null;
if (index >= 0)
newString = fileName.substring(index, fileName.length());
if ( newString.equalsIgnoreCase( ".txt"))
if ( dirList[count].isDirectory())
out.println( dirList[count].getName() );
else
out.println( dirList[count].getName());
}//end else
}// end if newstring
}//end if index
}//end for -
URGENT : getting attribute of files in a directory
Hello.
I use oracle 8i and I want to get attributes of files inside a directory like the "Modified" attribute which indicates the time of creation of the file.
How can I do this ?
Thank you very much.Tom Kytes has an example with java callout
Directory List including modify date and times - casting the date problem
http://asktom.oracle.com/pls/ask/f?p=4950:8:5492560634257383293::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:7506780031005, -
LV project files view root directory
I want to understand the nature of the LabVIEW project files view root directory. I suppose the files there are installed by dotnet framework and LabVIEW and will be installed to the target machine by dotnet framework and LabVIEW installer, is it correct? I searched that mscorlib is a Microsoft DLL but I don't know why it has a LabVIEW icon.
mscorlib is the the fundamental assembly for the .NET Framework; critical for .NET integration into LabVIEW. the files shown in your screenshot shouldn't be installed in the project directory or the root of your drive; they should exist in the GAC. Windows (and thus LabVIEW) considers this a special folder. LabVIEW doesn't show this folder in your files list for this reason; they appear to be in "no folder".
Although why mscorlib has a LabVIEW icon - that's a good question. Given the amount of .NET integration in LabVIEW, mscorlib would be the key dependency for all of it regardless of the other actual .NET assemblies used. I guess they just gave it a LabVIEW icon because it would be so commonly in your dependencies list. -
How to list the files in a directory which are recently modififed few mins
Hi,
I need command to list the files in a directory which are modified few minutes ago in SunOS. like "find . -cmin 2 -print " which list files that are modified 2 mins ago in Linux platform.
Thanks in advance.
sudha85The find command that comes with solaris doesnt have the cmin operator. Only mtime whose option is days.
So install gnu find from sunfreeware which is the same one that comes with linux. -
Problem with getting a list of files in a directory
I'm trying to get a list of files in a particular directory. The problem is I'm also getting a listing of all the sub-directories too. Here is my code:
File directory = new File(dir);
File[] filelist;
filelist = directory.listFiles();
for(int i=0;i<filelist.length;i++)
System.out.println("FileName = " + filelist.getName());
What am I doing wrong?
Thanks
BradYou are not doing anything wrong. You just have to test whether a given file is a subdirectory:
File directory = new File(dir);
File[] filelist;
filelist = directory.listFiles();
for(int n = 0; n < filelist.length; n++) {
if (!filelist[n].isDirectory())
System.out.println("FileName = " + filelist[n].getName());
}Søren Bak -
List of files in a directory of app server
Hi,
I was trying to get the list of all files in a directory using fm "EPS2_GET_DIRECTORY_LISTING". But the date column is empty in the output table. I also tried fm's
SUBST_GET_FILE_LIST
EPS_GET_FILE_ATTRIBUTES
none of the above is giving date.
Can anyone tell me a fm which gives date along with other attributes?
Thanks in Advance.
Satishtry get something from the transaction AL11 source code: RSWATCH0 form -> fill_file_list
Regards,
Vincent -
Too many files in root directory. How to split them up?
Hi,
I made my site http://isuckatgolf.net in Dreamwever cs3. Having no idea what I was doing when I started 5 years ago all images and pages have been uploaded directly to the root folder/directory. My host GoDaddy.com just sent me a notice that I'm only allowed 1024 folders/files in one directory. I have almost 7000 in the main site and 1500 in the database for the sub-domain/forum (SMF forum). According to Godaddy.com this is a rule of theirs, but it isn't posted anywhere that they could point me to. Only that I have a max. of 500,000 files total in my unlimited shared hosting account.
I'm looking for a new host that can handle the way it is set up today. My question is, IF I have to divide these files up into subfolders or directories (whatever they're technically called), is it possible and is there an "easy" way to do this in Dreamweaver. Obviously manually moving 7000 files will take some time. But can it be done, and do you think it will be necessary no matter who hosts the site?
Lastly, if I do find a host that is ok the way it is, going forward should I direct DW to put future images into an images folder of some kind. I never created one. Right now all the jpg, gif and html files are just listed. (I didn't know how to do it the right way when I started!)
Any help would be apprecaited.
Thanks!
KEnIt does not make any difference where your files are stored as long as the path to the file is correct. Nancy's idea is correct, but you can have sub-folders to the sub-folders. For example, I will have an images folder and within the images folder I will have folders that refer to pages within my site. My images folder may look like
+images
+index
+thumbs
+slides
+gallery
+holidays2012
+thumbs
+images
+holidays2013
+thumbs
+images
+golf
+images
etc, etc.
That way it is easy to discover if there are any redundant images.
The same goes for the pages. You may have a products page with a couple of sub-pages. The directory would the be
index.html
aboutus.html
products.html
contactus.html
+products
fencing_material.html
sport_clothing.html
solar_panels.html
etc, etc
As said, it really does not matter where the files are, with the exception of the index page which must always be in the root directory.
Good luck -
Getting list of directories within a directory - NULL
I am getting a NULL POINTER EXCEPTION when trying to get a list of directories from a directory.
<%
main_dir = new File("test_dir");
dirs = main_dir.list();
if(dir==null){
%>
ERROR: dirs is null<p>
Main Dir: <%=index_dir%>
<% }
%>
It is returning that message that dirs is null.
The directory structure is
$TOMCAT_DIR/webapps/test_dir.jsp
$TOMCAT_DIR/webapps/test_dir
Within test_dir are two directories: test1, test2
I put the same code into a regular java code:
File f = new File ("test_dir");
String[] dirs = f.list();
if(dirs == null){
System.out.println("dirs is null");
It DOES NOT print out that message that dirs is null.
I'm just very confused. What am I doing wrong?Pardon me but since I don't put the actual code on here sometiems there are typos.
I have a program where I open a directory. It's a search page where it displays about 10 results then has a button at the bottom says "next" for the next results.
Anyhow, one minute the webpage will be fine, open the directory with no problem. Then it will stop and say it can't open the directory when the directory is there. It's driving me nuts.
I'm using Java code within the JSP page, instead of beans so I dont' know if that causes some kind of error.
<%
index_dir = new File(master_index_dir);
indexes = index_dir.list();
if(indexes==null){
%>
ERROR: indexes is null<p>
Master Index Dir: <%=index_dir%>
<% }
else {
// Other stuff
%>
Well just 5 minutes ago this worked fine, the index was open and the results shown. However just 2 minutes ago it stopped and returns the message that indexes is null.
Sometimes if I stop and start tomcat several times it starts to work again. -
List all files in a directory, not including the sub directories if any
Hi,
I have been looking around php.net for a bit and can not work
out how i list the files that are in a directory i.e.
www.site.com/directory/
I would like the names of each file to be placed in an array,
but not to have the sub directories in this list should there be
any.
I was given some code a while ago that done this but it
listed the sub directories and i would like them not in this list.
I do not have this code anymore and do not know where i got
it, so i can not get it amended to what i need.
please can someone tell me what line of code i should be
using.
thank you in advance for your help.(_seb_) wrote:
> not very clever wrote:
>> Hi,
>>
>> I have been looking around php.net for a bit and can
not work out how
>> i list the files that are in a directory i.e.
>>
>> www.site.com/directory/
>>
>> I would like the names of each file to be placed in
an array, but not
>> to have the sub directories in this list should
there be any.
>>
>> I was given some code a while ago that done this but
it listed the
>> sub directories and i would like them not in this
list.
>>
>> I do not have this code anymore and do not know
where i got it, so i
>> can not get it amended to what i need.
>>
>> please can someone tell me what line of code i
should be using.
>>
>> thank you in advance for your help.
>>
>>
>>
>
> The follwoing PHP code will do just that. Just replace
"pathToFolder"
> with the path to your folder.
> I made the list of files also link to each file. Just
remove the link
> echo if you don't them to be links.
>
> <?php
> // FUNCTION TO LIST FILES:
> function listFiles($path){
> if($handle = opendir($path)){
> while(false !== ($file = readdir($handle))){
> if (is_file($path.'/'.$file) &&
!preg_match('/^\./',$file)){
> $files_array[]=$file;
> }
> }
> }
> return($files_array);
> }
> $path = 'pathToFolder';
>
> // CALL THE FUNCTION:
> $files_array = listFiles($path);
> foreach($files_array as $file){
> echo '<p><a
href="'.$path.'/'.$file.'">'.$file,'</a></p>';
> }
>
> ?>
>
I spotted one error:
foreach($files_array as $file){
echo '<p><a
href="'.$path.'/'.$file.'">'.$file,'</a></p>';
should be:
foreach($files_array as $file){
echo '<p><a
href="'.$path.'/'.$file.'">'.$file.'</a></p>';
(a dot after $file, not a coma)
seb ( [email protected])
http://webtrans1.com | high-end web
design
Downloads: Slide Show, Directory Browser, Mailing List
Maybe you are looking for
-
I just went to go pick up my droid x at the time they told me to... waited 30 minutes before someone would assist me. then they tell me I can't upgrade my phone because I am not elligible (when I clearly am because of the droid x early upgrade). So 1
-
Valuation type in case of stock transport order
Hi, We are spilt valuation. now we are doing stock transport order and it is asking for valuation type. while we dont want to enter valuation type in STO. as which material is to sent to plant, we know at that time of delivery. but during making STO
-
My daughter's 13" late 2011 MacBook Pro has frozen (null sign displays) after Yosemite installation. I can, however, boot from a clone of my MacBook Air that is on an external drive. I reinstalled Yosemite on the MBP HD, but it still hangs in mid ins
-
The data screen-sweeper in Mozilla seems to be blocked by some sites I need to log into, since Mozilla security does not input username and password data. How do I input this info thru Options/Security/Saved Passwords tab for these sites? Thanks!
-
Can't restore recent bookmark tag, despite restoring recent tags and most visited
Hi there, I recently lost my 'recent bookmarks' and 'recent tags' from my bookmarks folder. I searched help on the forums and followed the advice to restore the smart bookmarks folder (going to about:config, double-clicking on the smartbookmarks link