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.
Similar Messages
-
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)
-
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 -
Al11 - List of Directories and of Directory Parameters
Hello, dear colleagues,
I would likei to use transaction AL11 in order to read files from a recently created directory.
Does anyone of you know by chance how a can assign an existing directory to a logical directory parameter?
How can I make this parameter appear in the list of directory parameters appearing in the first screen of Al11?
Many thanks and best regards
StefanHi Click the button configure which appears in the first screen of all11.
-
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 -
Query to get list of queries within a specific session.
Hi all,
I want to know the query which will return me all the queries within a session. I have a query which I use quite often, but it returns the last query executed within that session.
select st.sql_text
from v$sqltext st,v$session sn where st.address=sn.sql_address and st.hash_value=sn.sql_hash_value and
sn.sid = <sid> and
sn.serial# = <serial#>
order by st.piece
Could anybody help me.
thanx,Hi,
Thanx.
I have one more query, does oracle server keep cursors open till end of the transaction or close it immediately as soon as query is successfully executed ? If it's not closing the cursors immediately, why the following query where I am joining v$sqltext, v$session and v$open_cursor is not retruning me all the queries in one transaction. I believe, transaction is queries executed between two successive commit / rollback. The following query is returning me the same resultset as the earlier one.
select oc.sql_text from v$session sn, v$open_cursor oc where sn.sql_address = oc.ADDRESS and sn.sql_hash_value = oc.HASH_VALUE and sn.sid = 8 and sn.serial#= 22769;
Thanx, -
FM to get list of all directories and files on application server..
Hi All,
Can anyone tel me FM to get list of all directories and files on application server..i know 'F4_DXFILENAME_TOPRECURSION'
and '/SAPDMC/LSM_F4_SERVER_FILE' these are working too...but my requirement is when i click F4 i should get list of directories and whn i select one of these the only directory name should display.....and whn click again for 2nd text box field i want file name ...means directory name in one text box field and file name in another....plz help me out..
helpful answers wil b awarded.
Thanks,
JayshreeHi Jayashree
Please check this FM, SUBST_GET_FILE_LIST. Pass the file path and file name, if it returns an entry in table FILE_LIST, then the filename and path are valid.
Hope this helps !
~ Ranganath -
Okay I want to be able to run a .cmd file from my workstation to query a certain folder on remote clients. I want the command to find the specific folder within another folder and display the current date modified of that folder. I was
able to use a command prompt to list the subdirectory that I was looking for on a specific computer by using the
DIR command. It was something like this:
dir C:\ParentFolder\ChildFolder /ad /o-d /b
This shows a list of directories within the "ChildFolder" directory. The output would be something like:
dir C:\ParentFolder\ChildFolder /ad /o-d /b
folder1
folder2
folder3
folder4
So what I need now is a way to just show the folder in this group that had the most recent modification. For example if "folder2" was the most recently modified folder in the group, I would like my command line to just display "folder2 04/08/14
04:13 PM
Any help would be greatly appreciated.
Cheers!Thanks Mike! This is what I was looking for! Much appreciated!
I would like to run this as a script from my admin workstation that will query clients that have the "ChildFolder" directory. Is there a way to output the results to a .log/.txt file? I was working on .cmd that looked like this:
{REM Verify current folder on remote clients
del current-folder.log
ECHO WorkStation-1 >> CurrentFolder/current-folder.log 2>&1
ECHO ---------------- >> CurrentFolder/current-folder.log 2>&1
DIR \\WorkStation-1\C$\ParentFolder\ChildFolder /ad /o-d /b >> CurrentFolder/current-folder.log 2>&1
ECHO ---------------- >> CurrentFolder/current-folder.log 2>&1}
My results looked something like this:
" WorkStation-1
Folder1
Folder2
Folder3
I know it's ugly, but it was working (somewhat). I just needed to list only the most recently modified folder. Anyway, I've rambled enough.
Is there a way to get my desired results using the PS command that you provided me? -
How do I get a list of directories and sub-directories?
Hi All,
I'm new to Java and have a couple of questions that are really stumping me and I sure could use some help.
Question 1:
I have this class file that I want to return back me a list of directories and only directories, not files. I can't figure out how to do this. I know I need to use the isDirectory() function but I can't figure out how to use it. The class file currently is returning back both directories and files. Please help!
Question 2:
Once I get the list of directories, I need to also get a listing of all subdirectories to form a directory tree starting at my File dir value (example: C:\Windows) in the constructor. Any ideas?
Thanks
import java.io.*;
public class DirList {
private String list = "";
public DirList(File dir){
File f = new File(dir.toString());
String[] files = f.list();
for ( int i=0;i<files.length; i++ ){
list += files[i] + "\n";
} // end for
} // end constructor
public String getList(){
return list;
} // end method getList
} // end class DirListI'm not familiar of the recursion technique that you speek of. If
this would work, please share it with me.Okay, i'll try, I assume that you don't care what level a subfolder is right! With a selected folder (from fileChooser), you want to obtain a list of all subfolders.
After you have select a folder from the filechooser
import java.io.File;
import java.util.ArrayList;
public class AllSubFolders
private static ArrayList allSubFolders = new ArrayList();
public static void main(String [] args) {
File selectedFolder = ....; //a folder seleted from the filechooser
getSubFolder(selectedFolder );
public static void getSubFolder(File aFolder) {
File[] file = aFolder.listFiles();
for (int n = 0; n < file.length; n++) {
if (file[n].isDirectory()){
allSubFolders.add(file[n]);
System.out.println(file[n].getAbsolutePath());
getSubFolder(file[n]); //recursion method call
}You can see that getSubFolder() method call it self, it will do right down to the end of the tree, try it out by replacing the line
File selectedFolder = ....; to
File selectedFolder = new File("c:\\yourFolder\\"); -
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. -
How to list all files and directories in another directory
I need to be able to list all the directories and files in a directory. I need to write a servlet that allows me to create an html page that has a list of files in that directory and also list all the directories. That list of files will be put into an applet tag as a parameter for an applet that I have already written. I am assuming that reading directories/files recursively on a web server will be the same as reading directories/files on a local system, but I don't know how to do that either.
Hi,
Here is a method to rotate through a directory and put all the files into a Vector (files).
* Iterates throught the files in the root file / directory that is passed
* as a parameter. The files are loaded into a <code>Vector</code> for
* processing later.
* @param file the root directory or the file
* that you wish to have inspected.
public void loadFiles(File file) {
if (file.isDirectory()) {
File[] entry= file.listFiles();
for (int i= 0; i < entry.length; i++) {
if (entry.isFile()) {
//Add the file to the list
files.add(entry[i]);
} else {
if (entry[i].isDirectory()) {
//Iterate over the entries again
loadFiles(entry[i]);
} else {
if (file.isFile()) {
//Add the file
files.add(file);
See ya
Michael -
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; -
When you have a list or blog within a box on a page, how do you get it to scroll within the box?
Thanks so much! Whatever I was trying only worked randomly. You made my day!
-
Trying to get multiple cell values within a geometry
I am provided with 3 tables:
1 - The GeoRaster
2 - The geoRasterData table
3 - A VAT table who's PK is the cell value from the above tables
Currently the user can select a point in our application and by using the getCellValue we get the cell value which is the PK on the 3rd table and this gives us the details to return to the user.
We now want to give the worst scenario within a given geometry or distance. So if I get back all the cell values within a given geometry/distance I can then call my other functions against the 3rd table to get the worst scores.
I had a conversation open for this before where JeffreyXie had some brilliant input, but it got archived while I was waiting on Oracle to resolve a bug (about 7 months)
See:
Trying to get multiple cell values within a geometry
If I am looking to get a list of cell values that interact with my geometry/distance and then loop through them, is there a better way?
BTW, if anybody wants to play with this functionality, it only seems to work in 11.2.0.4.
Below is the code I was using last, I think it is trying to get the cell values but the numbers coming back are not correct, I think I am converting the binary to integer wrong.
Any ideas?
CREATE OR REPLACE FUNCTION GEOSUK.getCellValuesInGeom_FNC RETURN VARCHAR2 AS
gr sdo_georaster;
lb blob;
win1 sdo_geometry;
win2 sdo_number_array;
status VARCHAR2(1000) := NULL;
CDP varchar2(80);
FLT number := 0;
cdl number;
vals varchar2(32000) := null;
VAL number;
amt0 integer;
amt integer;
off integer;
len integer;
buf raw(32767);
MAXV number := null;
r1 raw(1);
r2 raw(2);
r4 raw(200);
r8 raw(8);
MATCH varchar2(10) := '';
ROW_COUNT integer := 0;
COL_COUNT integer := 0;
ROW_CUR integer := 0;
COL_CUR integer := 0;
CUR_XOFFSET integer := 0;
CUR_YOFFSET integer := 0;
ORIGINY integer := 0;
ORIGINX integer := 0;
XOFF number(38,0) := 0;
YOFF number(38,0) := 0;
BEGIN
status := '1';
SELECT a.georaster INTO gr FROM JBA_MEGARASTER_1012 a WHERE id=1;
-- first figure out the celldepth from the metadata
cdp := gr.metadata.extract('/georasterMetadata/rasterInfo/cellDepth/text()',
'xmlns=http://xmlns.oracle.com/spatial/georaster').getStringVal();
if cdp = '32BIT_REAL' then
flt := 1;
end if;
cdl := sdo_geor.getCellDepth(gr);
if cdl < 8 then
-- if celldepth<8bit, get the cell values as 8bit integers
cdl := 8;
end if;
dbms_lob.createTemporary(lb, TRUE);
status := '2';
-- querying/clipping polygon
win1 := SDO_GEOM.SDO_BUFFER(SDO_GEOMETRY(2001,27700,MDSYS.SDO_POINT_TYPE(473517,173650.3, NULL),NULL,NULL), 10, .005);
status := '1.2';
sdo_geor.getRasterSubset(gr, 0, win1, '1',
lb, win2, NULL, NULL, 'TRUE');
-- Then work on the resulting subset stored in lb.
status := '2.3';
DBMS_OUTPUT.PUT_LINE ( 'cdl: '||cdl );
len := dbms_lob.getlength(lb);
cdl := cdl / 8;
-- make sure to read all the bytes of a cell value at one run
amt := floor(32767 / cdl) * cdl;
amt0 := amt;
status := '3';
ROW_COUNT := (WIN2(3) - WIN2(1))+1;
COL_COUNT := (WIN2(4) - WIN2(2))+1;
--NEED TO FETCH FROM RASTER
ORIGINY := 979405;
ORIGINX := 91685;
--CALCUALATE BLOB AREA
YOFF := ORIGINY - (WIN2(1) * 5); --177005;
XOFF := ORIGINX + (WIN2(2) * 5); --530505;
status := '4';
--LOOP CELLS
off := 1;
WHILE off <= LEN LOOP
dbms_lob.read(lb, amt, off, buf);
for I in 1..AMT/CDL LOOP
if cdl = 1 then
r1 := utl_raw.substr(buf, (i-1)*cdl+1, cdl);
VAL := UTL_RAW.CAST_TO_BINARY_INTEGER(R1);
elsif cdl = 2 then
r2 := utl_raw.substr(buf, (i-1)*cdl+1, cdl);
val := utl_raw.cast_to_binary_integer(r2);
ELSIF CDL = 4 then
IF (((i-1)*cdl+1) + cdl) > len THEN
r4 := utl_raw.substr(buf, (i-1)*cdl+1, (len - ((i-1)*cdl+1)));
ELSE
r4 := utl_raw.substr(buf, (i-1)*cdl+1, cdl+1);
END IF;
if flt = 0 then
val := utl_raw.cast_to_binary_integer(r4);
else
val := utl_raw.cast_to_binary_float(r4);
end if;
elsif cdl = 8 then
r8 := utl_raw.substr(buf, (i-1)*cdl+1, cdl);
val := utl_raw.cast_to_binary_double(r8);
end if;
if MAXV is null or MAXV < VAL then
MAXV := VAL;
end if;
IF i = 1 THEN
VALS := VALS || VAL;
ELSE
VALS := VALS ||'|'|| VAL;
END IF;
end loop;
off := off+amt;
amt := amt0;
end loop;
dbms_lob.freeTemporary(lb);
status := '5';
RETURN VALS;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001, 'GENERAL ERROR IN MY PROC, Status: '||status||', SQL ERROR: '||SQLERRM);
END;Hey guys,
Zzhang,
That's a good spot and as it happens I spotted that and that is why I am sure I am querying that lob wrong. I always get the a logic going past the total length of the lob.
I think I am ok using 11.2.0.4, if I can get this working it is really important to us, so saying to roll up to 11.2.0.4 for this would be no problem.
The error in 11.2.0.3 was an internal error: [kghstack_underflow_internal_3].
Something that I think I need to find out more about, but am struggling to get more information on is, I am assuming that the lob that is returned is all cell values or at lest an array of 4 byte (32 bit) chunks, although, I don't know this.
Is that a correct assumption or is there more to it?
Have either of you seen any documentation on how to query this lob?
Thanks -
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
Maybe you are looking for
-
How can I migrate Vista Mail to Thunderbird when Vista Mail has no export function?
I understand TB can directly import .eml messages and folders when they are exported correctly, but Windows Mail in Vista has no export facility. And the third-party TB add-on ImportExport Tools doesn't even list Windows Mail in its import window. Th
-
Final cut bug, interlacing when adding transitions
Hello So I have been experiencing a problem in final cut pro 6 when generating a timeline using motion jpeg A and using transitions that all clips end up looking interlaced. The fields in the sequence settings are set to non and all the settings are
-
Unable to Set Up Photosmart Printer with Google Cloud Print Services
I am attempting to set up my HP Photosmart 7520 for Google Cloud Print. Google instructions explain that I require my HP Printer email for eprint services. I am unable to find my HP eprint email. Can you please assist in this setup. My printer is
-
Lock and Unlock in fim 2010 r2
Hi, I define fallowing setting in Workflow. If the settings are set to Temporary Lockout (number of attempts) =2, Permanent Lockout (number of attempts)= 2, and Lockout Duration (minutes) =2, but this is not work for me.By default it is consider Per
-
Flash Catalyst doesn`t recognize installed fonts
Hi folks, got a little problem with my fonts inside of Catalyst 5.0 (working on Windows 7 64 bit prof.) I have a bunch of font-families installed on my system (Eurostile Font and DIN-Font) and these fonts are not recognize by Catalyst. I did some pag