List of files in directory
I need to access a list of files in a directory. The files are .js scripts that I want to dynamically insert into a page with JSP. The problem is that at my company these .js scripts will often be added/removed and it would simplify the process to just look at what's in the directory and pick out the appropriate .js that are available.
My directory structure is arranged something like this:
./src/jsp for the jsp pages
and
./conf/somescripts for the .js scripts.
I tried accessing it with getClass().getResource() to get the URL, and I also tried File(relativePathToSomescripts) but without much success - tends to get nulls in return. I'm not too experienced with JSP, but I'm guessing the relative paths change once Tomcat compiles them. So what would be a reliable way to access the list of files in the script directory?
The File constructor only accepts absolute URI's. You can get the absolute URI for the relative URI using ServletContext#getRealPath().
String absolutePath = servletContext.getRealPath(relativePath);
Similar Messages
-
List of Files in directory on AS
WEBUTIL.DIRECTORY_LIST gives me the list of files on the client. But I need List of Files in directory on App Server . My App server is on LINUX and client is Windows. So How can get through oracle forms a List of Files in directory on Application Server .
I will appreciate help ?I don't know if it helps you(if not excuse me)
look at
List of Files in directory on AS
Running HOST Commands
If you have a host command of the form:
HOST ('DEL c:\temp.txt')
This will work in both client/server and Web deployed environments, but in web
deployed environments the command runs on the middle tier.
in Linux ls -la > ..... -
Returning list of files in directory not working.
Gidday
I'm using the following code to try to put a listing of files in a dir into an array.
I created a dir call myDir in the same place as my .swf and .air, and placed a file in it. But I get error messages telling me the File or directory does not exist.
Why would this be?
var dir:File = File.desktopDirectory.resolvePath("myDir");
var files:Array = dir.getDirectoryListing();
Thanks for taking a look.OK (still trying to get my head around the folder structure)
Say my project exe is called test.exe, and I also have a folder called image_files and another called text_files - how do I access the image_files folder, and how do I write txt documents to the text_files folder? In other words, I don't want to access the user's folder, or the application storage folder, just specific folders that I have set up in my Flash as3 project.
Or does security prevent accessing and writing to such folders?
So how would I alter the following code to write to the text_files folder?
function saveHandler(event:Event):void {
var file:File = File.applicationStorageDirectory.resolvePath( "myjot.txt" );
var jot:String = taEditor.text;
var stream:FileStream = new FileStream();
stream.open( file, FileMode.WRITE );
stream.writeMultiByte( jot, File.systemCharset );
stream.close();
I want the user to be able to copy image and video files to the image_files folder, and then I have access to these in the air app. So I don't want to put them in the application Storage Directory because A) like you said, it's not designed for large amounts of data, and B) I don't want the user to have to navigate to the app data folder - I want to keep navigation simple - so program files/my app/image_files (or preferably give them the option of choosing the folder where they copy their image and video files to - so it could be on d) drive for example).
Thanks for your time and help
Shaun -
How can I get file list for a given directory?
Hi,
How can I get file list for a given directory? Is there a function?
Thanks.Hi friend,
Try this sample report. It displays all files in a directory.
While executing give some directory name in input. ex: C:\
Mention file type in filter parameter. ex: *.DOC
REPORT ztests.
DATA : file_table LIKE TABLE OF sdokpath WITH HEADER LINE .
DATA : dir_table LIKE TABLE OF sdokpath WITH HEADER LINE .
PARAMETERS:p_dir(50) TYPE c.
CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
EXPORTING
directory = p_dir
filter = '*.DOC'
TABLES
file_table = file_table
dir_table = dir_table
EXCEPTIONS
cntl_error = 1
OTHERS = 2.
LOOP AT file_table .
WRITE:/ file_table-pathname.
ENDLOOP.
Might be helpful...
Thanks.....
Edited by: Guest77 on Feb 11, 2009 5:30 AM -
Listing files of directory on application server
hi all,
I want to download a list of files from the application server.
I tried the functions:
- SUBST_GET_FILE_LIST
- EPS_GET_DIRECTORY_LISTING
- RZL_READ_DIR_LOCAL
but the result gives me the name of my file truncated.
My filename is much longer than the functions give me.
Is there any other function, or can i bypass this problem in a way.
Thanks in advance.
Merijn.Hello,
This is a common problem with this FMs. Even SAP acknowledges this:
In EPS_GET_DIRECTORY_LISTING you have this:
data: begin of file,
dirname(75) type c, " name of directory. (possibly truncated.)
name(75) type c, " name of entry. (possibly truncated.)
end of file.
The FM uses a Kernel Call 'C_DIR_READ_NEXT' to get the list of the files in the directory. The file name is returned in the field file-name.
call 'C_DIR_READ_NEXT'
id 'TYPE' field file-type
id 'NAME' field file-name
id 'LEN' field file-len
id 'OWNER' field file-owner
id 'MTIME' field file-mtime
id 'MODE' field file-mode
id 'ERRNO' field file-errno
id 'ERRMSG' field file-errmsg.
The program RSWATCH0(trxn: AL11) also uses the Kernel call but the structure file is different.
DIrectory name can be 1024 character long & file name is 260 character long
data: begin of file,
dirname(1024) type c, " name of directory. (possibly
" truncated.)
name(260) type c, " name of entry. (possibly
" truncated.)
type(10) type c, " type of entry.
len(8) type p, " length in bytes.
owner(8) type c, " owner of the entry.
mtime(6) type p, " last modification date, seconds since 1970
mode(9) type c, " like "rwx-r-x--x": protection mode.
useable(1) type c,
subrc(4) type c,
errno(3) type c,
errmsg(40) type c,
mod_date type d,
mod_time(8) type c, " hh:mm:ss
seen(1) type c,
changed(1) type c,
end of file.
So one workaorund would be to copy EPS_GET_DIRECTORY_LISTING to some custom FM & change the length of the structure file to suit your requirement
BR,
Suhas
PS: Use of Kernel Call is for internal use only & is highly not recommended by SAP. -
How to list the files I saved in //var/mobile/ApplicatiDocuments directory?
I want to list the JPG files in the directory of /var/mobile/Applications/XXXXXX/Documents. Have any API like [[NSBundle mainBundle] pathsForResourcesOfType:@"JPG" inDirectory:path]; to list the files? Thanks. Kevin.
I think you can just do something like this:
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"documentsDirectory=%@", documentsDirectory);
NSArray *docDirContents = [[NSFileManager defaultManager]
directoryContentsAtPath:documentsDirectory];
for (NSString *fileName in docDirContents)
if (![[fileName pathExtension] caseInsensitiveCompare:@"jpg"])
NSLog(@"fileName=%@", fileName);
- Ray -
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. -
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
-
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 -
Get the file list of a given directory
does anyone know how to get the file list of a given directory? I tried "list"/"filelist" but the class not found.
THanks!What made you assume that there exist classes called list or filelist etc.
Do you read API documentation etc ?
Anyways, here is a hint java.io.File.listFiles() -
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 -
Getting a list of files from a shared directory
Hi All,
I need to get a list of files from a shared directory on another server and put them in a HTMLB TableView element with links to the files.
I was not successful with CL_GUI_FRONTEND_SERVICES=>DIRECTORY_LIST_FILES. This method works in test mode, but gives me a gui_not_supported exception in BSP. I guess BSPs are not allowed to use this.
Is there any other alternative?
I need to be able to upload the files as well.
Thanks,
Roman
Message was edited by: Roman DubovHi again,
Not sure about the shared directory files list...
In my opinion, this cannot be done using BSP.
But, you can try using VBScript to access the file system with object of that sort :
CreateObject("Scripting.FileSystemObject")
it is only a thought and you can be sure to cross security problems by accessing files through a Web application...
Best regards,
Guillaume -
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 -
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. -
List all file names in a directory
Hello everybody,
I need to write a script in PL/SQL (oracle 10g) that lists all filenames in a specific directory on a client machine and import the files into the database (xml files). After the file is imported they have to be removed.
I was searching for a solution for this because I have never come accross a challenge like this.
What I found was that I could use the procedure dbms_backup_restore.searchfiles of the SYS schema.
Now I need to know how this procedure works. There is very little documentation available.
Can I give the procedure a folder name on my client computer that has the xml files and let the procedure list these files?
Can someone please help me with this. I haven't got a clue.
Thanks in advance.
regards,
MarianeHello Justin,
Thank you for your reply.
You have just confirmed what I already was thinking: that the server cannot read files from the client.
I haven't got a client application running to do this. My customer wants me to write a script in PL/SQL that enables users to run an import of xml files in the database by giving in a directory name on the client.
I told my customer that they have to put the xml files on a server directory. Should that always be the server where the database resides on?
Is there another way to solve this request?
Thanks in advance.
regards,
Mariane
Maybe you are looking for
-
My quicktime library folder disappeared, how do I get it back?
I was trying to install this XVID Codec for the application toast titanium in order for it to work. I found a file and it told me to put it in the library/quicktime folder, so I did. I restarted the computer and it didn't work. So I found another one
-
All, I need to upload every stock balances for a storage location in system . I am using batch management here .So in material master I am putting shelf life and Minimum remaining shelf life . So suppose for a material shelf life is 30 days and Min R
-
Memory leak in ldap_parse_ds_event
Hi, I'm doing some development with the eDir LDAP event API and noticed some memory leakage. Valgrind points the finger at ldap_parse_ds_event: ==32146== 220 bytes in 5 blocks are definitely lost in loss record 4 of 5 ==32146== at 0x401CCA0: calloc (
-
Editing 32bit Tiffs not possible ?
I have a 32-bit tiff file I want to edit, photoshop is only displaying a single black image. Opening the levels panel shows a single spike in the levels for black, white and gray are non-existent. Opening the image in RAW shows an ugly blotchy image,
-
How to clone 11gr2 grid and oracle homes
Hi, By mistake I have installed the software and the database under the same disk /u01. I should had installed the software under /u02 and the database + grid infrastructure for standalone server + Oracle restart under /u01. My database is 11gR2 on L