How to get list of file names from a directory?
How to get list of file names from a directory?
Please help
In 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.
Similar Messages
-
How to get the target file name from an URL?
Hi there,
I am trying to download data from an URL and save the content in a file that have the same name as the file on the server. In some way, what I want to do is pretty similar to what you can do when you do a right click on a link in Internet Explorer (or any other web browser) and choose "save target as".
If the URL is a direct link to the file (for example: http://java.sun.com/images/e8_java_logo_red.jpg ), I do not have any problem:
URL url = new URL("http://java.sun.com/images/e8_java_logo_red.jpg");
System.out.println("Opening connection to " + url + "...");
// Copy resource to local file
InputStream is = url.openStream();
FileOutputStream fos=null;
String fileName = null;
StringTokenizer st=new StringTokenizer(url.getFile(), "/");
while (st.hasMoreTokens())
fileName=st.nextToken();
System.out.println("The file name will be: " + fileName);
File localFile= new File(System.getProperty("user.dir"), fileName);
fos = new FileOutputStream(localFile);
try {
byte[] buf = new byte[1024];
int i = 0;
while ((i = is.read(buf)) != -1) {
fos.write(buf, 0, i);
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (is != null)
is.close();
if (fos != null)
fos.close();
}Everything is fine, the file name I get is "e8_java_logo_red.jpg", which is what I expect to get.
However, if the URL is an indirect link to the file (for example: http://javadl.sun.com/webapps/download/AutoDL?BundleId=37719 , which link to a file named JavaSetup6u18-rv.exe ), the similar code return AutoDL?BundleId=37719 as file name, when I would like to have JavaSetup6u18-rv.exe .
URL url = new URL("http://javadl.sun.com/webapps/download/AutoDL?BundleId=37719");
System.out.println("Opening connection to " + url + "...");
// Copy resource to local file
InputStream is = url.openStream();
FileOutputStream fos=null;
String fileName = null;
StringTokenizer st=new StringTokenizer(url.getFile(), "/");
while (st.hasMoreTokens())
fileName=st.nextToken();
System.out.println("The file name will be: " + fileName);
File localFile= new File(System.getProperty("user.dir"), fileName);
fos = new FileOutputStream(localFile);
try {
byte[] buf = new byte[1024];
int i = 0;
while ((i = is.read(buf)) != -1) {
fos.write(buf, 0, i);
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (is != null)
is.close();
if (fos != null)
fos.close();
}Do you know how I can do that.
Thanks for your help
// JB
Edited by: jb-from-sydney on Feb 9, 2010 10:37 PMThanks for your answer.
By following your idea, I found out that one of the header ( content-disposition ) can contain the name to be used if the file is downloaded. Here is the full code that allow you to download locally a file on the Internet:
* Download locally a file from a given URL.
* @param url - the url.
* @param destinationFolder - The destination folder.
* @return the file
* @throws IOException Signals that an I/O exception has occurred.
public static final File downloadFile(URL url, File destinationFolder) throws IOException {
URLConnection urlC = url.openConnection();
InputStream is = urlC.getInputStream();
FileOutputStream fos = null;
String fileName = getFileName(urlC);
destinationFolder.mkdirs();
File localFile = new File(destinationFolder, fileName);
fos = new FileOutputStream(localFile);
try {
byte[] buf = new byte[1024];
int i = 0;
while ((i = is.read(buf)) != -1) {
fos.write(buf, 0, i);
} finally {
if (is != null)
is.close();
if (fos != null)
fos.close();
return localFile;
* Returns the file name associated to an url connection.<br />
* The result is not a path but just a file name.
* @param urlC - the url connection
* @return the file name
* @throws IOException Signals that an I/O exception has occurred.
private static final String getFileName(URLConnection urlC) throws IOException {
String fileName = null;
String contentDisposition = urlC.getHeaderField("content-disposition");
if (contentDisposition != null) {
fileName = extractFileNameFromContentDisposition(contentDisposition);
// if the file name cannot be extracted from the content-disposition
// header, using the url.getFilename() method
if (fileName == null) {
StringTokenizer st = new StringTokenizer(urlC.getURL().getFile(), "/");
while (st.hasMoreTokens())
fileName = st.nextToken();
return fileName;
* Extract the file name from the content disposition header.
* <p>
* See <a
* href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html">http:
* //www.w3.org/Protocols/rfc2616/rfc2616-sec19.html</a> for detailled
* information regarding the headers in HTML.
* @param contentDisposition - the content-disposition header. Cannot be
* <code>null>/code>.
* @return the file name, or <code>null</code> if the content-disposition
* header does not contain the filename attribute.
private static final String extractFileNameFromContentDisposition(
String contentDisposition) {
String[] attributes = contentDisposition.split(";");
for (String a : attributes) {
if (a.toLowerCase().contains("filename")) {
// The attribute is the file name. The filename is between
// quotes.
return a.substring(a.indexOf('\"') + 1, a.lastIndexOf('\"'));
// not found
return null;
} -
How to get the long file name from an 8.3 name in Windows.
Because of a legacy string limitation, I have a list of files in 8.3 format. The actual files are saved with long names. How can I get the long name from the short name?
In JavaScript, I would get a file system object and get the file object from there with the short name. Then it's no problem to get the full name. But I don't see anything in Java that matches that. ???
Ideas?
Frank Perry, MSEEHere is what I did.
String displayName = "somefi~1.txt";
File fO = new File("c:\\"); // I have a more involved path but that's not important here.
String stPath = fO.getPath() + displayName;
File fD = new File(stPath); // get the file using the short name.
File fDc = new File(fD.getCanonicalPath()); // get another file using the cononical name
String FulldisplayName = fDc.getName(); // get the long name from there.
It's roundabout but it works. Since getName() on the file read with the short name only returns the name used to get the file, I open it twice. The alternative is to parse the cononical name for the file name but that's clumbsy too.
Frank -
How to get List Item attachments name without write any custom code or any database query?
Hi,
How to get List Items attachments name without write any custom code or any database query?You can get it from Rest,
There are 2 options,
1) create a 'Result Source' which has a search query for that List which has attachments
- Use rest query to get the 'Filename' , it will have the attachment file name
For example, if the result source id is : 73e6b573-abf8-4407-9e5f-8a85a4a95159 , then the query will be
http://[site URL]/_api/search/query?querytext='*'&selectproperties='Title,Path,FileExtension,SecondaryFileExtension,Filename'&sourceid='73e6b573-abf8-4407-9e5f-8a85a4a95159'&startrow=0&rowLimit=100
You can refine the query, be giving proper 'querytext'
2) Use the List rest api
For example if your list guid is :38d524a1-e95c-439f-befd-9ede6ecd242e
You can get he attachments for 1st item using this
http://[Site URL]/_api/lists(guid'38d524a1-e95c-439f-befd-9ede6ecd242e')/items(1)/AttachmentFiles
get2pallav
Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you. -
How can I assign image file name from Main() class
I am trying to create library class which will be accessed and used by different applications (with different image files to be assigned). So, what image file to call should be determined by and in the Main class.
Here is the Main class
import org.me.lib.MyJNIWindowClass;
public class Main {
public Main() {
public static void main(String[] args) {
MyJNIWindowClass mw = new MyJNIWindowClass();
mw.s = "clock.gif";
And here is the library class
package org.me.lib;
public class MyJNIWindowClass {
public String s;
ImageIcon image = new ImageIcon("C:/Documents and Settings/Administrator/Desktop/" + s);
public MyJNIWindowClass() {
JLabel jl = new JLabel(image);
JFrame jf = new JFrame();
jf.add(jl);
jf.setVisible(true);
jf.pack();
I do understand that when I am making reference from main() method to MyJNIWindowClass() s first initialized to null and that is why clock could not be seen but how can I assign image file name from Main() class for library class without creating reference to Main() from MyJNIWindowClass()? As I said, I want this library class being accessed from different applications (means different Main() classes).
Thank you.Your problem is one of timing. Consider this simple example.
public class Example {
public String s;
private String message = "Hello, " + s;
public String toString() {
return message;
public static void main(String[] args) {
Example ex = new Example();
ex.s = "world";
System.out.println(ex.toString());
}When this code is executed, the following happens in order:
1. new Example() is executed, causing an object to constructed. In particular:
2. field s is given value null (since no value is explicitly assigned.
3. field message is given value "Hello, null"
4. Back in method main, field s is now given value "world", but that
doesn't change message.
5. Finally, "Hello, null" is output.
The following fixes the above example:
public class Example {
private String message;
public Example(String name) {
message = "Hello, " + name;
public String toString() {
return message;
public static void main(String[] args) {
Example ex = new Example("world");
System.out.println(ex.toString());
} -
How to get customer number and name from the SD document
Hi All,
Can you please let me know how to get Customer Number and Name from the SD Document?
Thanks a lot....
AnilHi,
It will be displayed in the SD (BIlling document) itself, you clikc on the VF03. The customer name and number will also appear in the SO document also Tcode VA03
regards,
radhika
Edited by: kolipara radhika on Jul 10, 2009 5:32 AM -
How to get the Portal Page name from PLSQL?
Can anyone tell me how to get the portal page name from my dynamic page using plsql?
Apparently you can get the page id and work it out from there, but my calls to get the page id are not returning any values anyway.
My code for attempting to get the page id is below.
<oracle>
declare
v_pageid varchar2(30);
begin
v_pageid := wwpro_api_parameters.get_value('_pageid', '/pls/portal30');
htp.print('Page is '|| v_pageid);
end;
</oracle>
Ideally I'd actually just like to get the page name. Is there a straightforward way to do this?
Thanks in advance!
SarahFew clarifications -
1. wwpro_api_parameters cannot be used to get default portal
page parameters such as '_pageid', '_dad', '_schema' etc.,
2. Page information can be obtained through any components which
are available in that particular page. For example, in case of
dynamic page, we need to publish it as a portlet and add it to the
page. This process creates necessary packages in the DB, but we
will not have access to the portlet methods.
So, I would prefer creating a simple DB provider & portlet and access
page title from its show method as follows -
//Declare local variable l_page_id, l_page_title as varchar2
select page_id into l_page_id from wwpob_portlet_instance$ where
portlet_id = p_portlet_record.portlet_id and
provider_id = p_portlet_record.provider_id;
select name into l_page_title from wwpob_page$ where id=l_page_id;
More information on DB provider can be found at
http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/articles/understanding.database.providers.html
Secondly, usage of wwpro_api_parameters.get_value method is
incorrect. This method expects two arguments -
<ul>
<li><b>p_name : </b> The name of the parameter to be returned.</li>
<li><b>p_reference_path : </b> An unique identifier for a portlet instance on the current page.</li>
</ul>
p_reference_path would be something like 99_SNOOP_PORTLET_76535103 and not some type of path as its name suggests.
The following code fragment fetches all parameters available
for a portlet.
Note : Copy this code into 'show' method of your portlet.
//Declare l_names, l_values as owa.vc_arr
* Retreive all of the names of parameters for this portlet
l_names := wwpro_api_parameters.get_names(
p_reference_path=>p_portlet_record.reference_path);
* Retreive all of the values of parameters for this portlet
l_values := wwpro_api_parameters.get_values(p_names=>l_names,
p_reference_path=>p_portlet_record.reference_path);
//Loop through these arrays to get parameter information
htp.p('<center><table BORDER COLS=2 WIDTH="90%" >');
htp.p('<tr ALIGN=LEFT VALIGN=TOP>');
htp.tableData(wwui_api_portlet.portlet_heading('Name',1));
htp.tableData(wwui_api_portlet.portlet_heading('Value',1));
htp.tableRowClose;
if l_names.count = 0 then
htp.p('<tr ALIGN=LEFT VALIGN=TOP>');
htp.p('<td COLSPAN="2">'
||wwui_api_portlet.portlet_text(
'No portlet parameters were passed on the URL.',1)
||'</td>');
htp.tableRowClose;
else
for i in 1..l_names.count loop
htp.p('<tr ALIGN=LEFT VALIGN=TOP>');
htp.tableData(l_names(i));
htp.tableData(l_values(i));
htp.tableRowClose;
end loop;
end if;
htp.p('</table></center>');
Hope it helps...
-aMJAD. -
Can we possible to retrive the file name from the directory...?
Can we possible to retrive the list of files or file names from the directory...?
The directory called create or replace directory [directory_name] as ....Yeah, yeah its very good example for this scenario.
I agree. But, I want to learn about Java based PL/SQL code development for that just I am asking any link for this kind of material.....:-) -
How to get the actual font name from a font file?
Hi
I have only the font Path I have to get the font name from that path. Any idea how to get the actual font name?
Thanks,I would ask you these questions:
Why do you need to do this? What are you ultimately trying to accomplish?
Are you really asking about the InDesign SDK?
Do you really need to get the "name" of a font from an arbitrary file? Or do you want information about a font installed on the system? If so, what OS?
Do you need to be able to handle any font format?
Which font "name" do you mean?
What language do you want the name in?
(1) It's not clear what you're trying to accomplish. A bit more information about your ultimate goal would be helpful.
(2) This question is not at all specific to the InDesign SDK. Are you really trying to do something in the context of an InDesign plug-in? If so, you probably want to look at IID_IFONTFAMILY and the IFontFamily::GetFamilyName function.
(3) If you are asking more generally, Windows and Mac both have system API calls to get this information, although those tend to deal with installed system fonts, not with arbitrary font files per se.
Also, you can parse the name table from a True Type or Open Type font without using any system APIs; as True Type and Open Type are well-documented standards. I would start by reading these:
The Naming Table
Font Names Table
(4) Although there are other standards, such as Type 1 (PostScript) fonts, and True Type Collection files and other formats, especially on Mac.
(5) Also, when you start down this road, you will quickly realize that your seemingly simple question is actually ambiguous, and that the answer is kind of complicated, because a font can have many names (a family name, a full font name, a style name, a PostScript name, etc.).
(6) And not only does a font have multiple names, it can have each of those names in multiple languages and encodings.
Any clarification would make this a better question. -
How to get the Output File Name as One of the Field Value From Payload
Hi All,
I want to get the Output file name as one of the Field value from payload.
Example:
Source XML
<?xml version="1.0" encoding="UTF-8" ?>
- <ns0:MT_TEST xmlns:ns0="http://sample.com">
- <Header>
<NAME>Bopanna</NAME>
</Header>
</ns0:MT_TEST>
I want to get the Output file name as " Bopanna.xml"
Please suggest me on this.
Regards
BopannaHi,
There are couple of links already available for this. Just for info see the below details,
The Output file name could be used from the field value of payload. For this you need to use the UDF DynamicFile name with below code,
// Description: Function to create dynamic Filename
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File" , "FileName");
conf.put(key,a);
return "";
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File" , "FileName");
conf.put(key,a);
return "";
With this udf map it with the MessageType as
(File Name field from Payload) > DynamicFileConfiguration>MTReceiver
Thanks
Swarup -
How to find list or folder name from SharePoint document URL
I'm implementing the SharePoint client object model in my VSTO application in .NET framework 4.0(C#).
Actually we open MS Word files from SharePoint site, we need to create a folder inside the opened documents list/folder and after it we want to upload/add some files to that created folder.
My problem is that how to get list name/title and folder name of opened document by using the documents URL or Is there an another option to find the list or folder name of opened document.
Any help will be appreciable.In document Library you can get the name of document library directly in URL. for folder name you can try below:
using System;
using Microsoft.SharePoint;
namespace Test
class ConsoleApp
static void Main(string[] args)
using (SPSite site = new SPSite("http://localhost"))
using (SPWeb web = site.OpenWeb())
if (web.DoesUserHavePermissions(SPBasePermissions.BrowseDirectories))
// Get a folder by server-relative URL.
string url = web.ServerRelativeUrl + "/shared documents/test folder";
SPFolder folder = web.GetFolder(url);
try
// Get the folder's Guid.
Guid id = folder.UniqueId;
Console.WriteLine(id);
// Get a folder by Guid.
folder = web.GetFolder(id);
url = folder.ServerRelativeUrl;
Console.WriteLine(url);
catch (System.IO.FileNotFoundException ex)
Console.WriteLine(ex.Message);
Console.ReadLine();
http://msdn.microsoft.com/en-us/library/office/ms461676(v=office.15).aspx
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/801d1a06-0c9b-429b-a848-dd6e24de8bb9/sharepoint-webservice-to-get-the-guid-of-the-folder?forum=sharepointdevelopmentlegacy
You can also try below:
http://blogs.msdn.com/b/crm/archive/2008/03/28/contextual-sharepoint-document-libraries-and-folders-with-microsoft-dynamics-crm.aspx
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/d2d5d7cf-9bbd-4e0f-a772-ecdce4e6149f/how-to-fetch-document-guid-from-sharepoint-document-library-using-sharepoint-web-service?forum=sharepointdevelopmentlegacy
http://stackoverflow.com/questions/2107716/how-to-get-guid-of-a-subfolder-in-a-document-library-programmatically -
How to create Dynamic Selection List containg file names of a directory?
Hi,
I need a Selection List with a Dynamic List of Values containing all file names of a particular directory (can change through the time).
Basically, I need an Iterator over all file names in a directory, which could be used for Selection List in a JSF form.
This iterator has nothing to do with a database, but should get the names directly from the file system (java.io.File).
Can anybody tell me how to create such an iterator/selection list?
I am working with JDeveloper 10.1.3.2, JSF and Business Services.
Thank you,
IgorCreate a class like this:
package list;
import java.io.File;
public class fileList {
public fileList() {
public String[] listFiles(){
File dir = new File("c:/temp");
String[] files = dir.list();
for (int i = 0; i < files.length; i++) {
System.out.println(files);
return files;
Right click to create a data control from it.
Then you can drag the return value of the listFiles method to a page and drop as a table for example.
Also note that the Content Repository data control in 10.1.3.2 has the file system as a possible data source. -
How to get the failover partner name from C++ client
Hi All,
I have configured the mirroring session for my application.
I want to modify the connection string with failover partner name.
Could any one please let me to know how to get the failover partner instance from C++ client dynamically.
Thanks,
Prasad.Are you looking for this?
http://www.connectionstrings.com/sql-server-2012/
http://stackoverflow.com/questions/25534972/auto-failover-multiple-connections-to-mirror-database-when-principal-goes-down -
How to get Driver and url names from a connection pool
Hi,
How to get the DriverName and URL from an existing pool, If I know the name of
connection pool ? Is it possible to know the name of related pool , if I know
the name of datasource?
Thx
Manishhi
there are 2 ways:
url must be: jdbc:weblogic:pool[:connectionPoolID]
or
jdbc:weblogic:jts[:connectionPoolID] (if you want to use jts with your JDBC connection.)
see http://e-docs.bea.com/wls/docs60//javadocs/weblogic/jdbc/pool/Driver.html
However, I think it is safer to configure and use DataSource to get connection.
Nicolas
"kumar" <[email protected]> wrote:
>
Hi,
How to get the DriverName and URL from an existing pool, If I know the name
of
connection pool ? Is it possible to know the name of related pool , if I
know
the name of datasource?
Thx
Manish -
How to get the SQL file name in SQL*plus
hi all,
I have created two sql file at C drive as "c:\Createtable.sql" and "c:\Deletetable.sql"
afterwards i open
C:\>sqlplus
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jan 30 11:37:10 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter user-name: scott/tiger
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> @C:\Createtable.sql'
Table created.
SQL> @'C:\Deletetable.sql'
Table dropped.
SQL>My problem is to get the name of the file as "c:\createtable.sql" and "C:\Deletetable.sql" in sql*plus enviornment.
Thanks & Regards
SinghDear Damorgan,
>>your version number to three decimal places
My Oracle DB Version i have already stated in my previous post is 10.2.0.1.0
Actually my problem is to get the sql files name we run in sqlplus enviornment with @ symbol. like
i have created one sql file in c drive as
"C:\Createtable.sql"
afterwords i have connected to sqlplus as
sql> conn scott/tiger
sql>@c:\createtable.sql
Now i want some query to get the name of the file which is run.
In actual my problem is as
i have suppose 10 or more SQL files in some folder ( sql1.sql, sql2.sql, sql3.sql ....).
i created one file to call all the 10 sql files (main.sql)
i have also one track_table which will keep track that which sql file is runned.
I want some automated script which will insert the record in that track_table....... for that i need the name of sql file which is runned.
Hope this will help you.
Thanks & Regards
Singh
Maybe you are looking for
-
Can not disconnect fron VPN in Windows 8.1
I just bought a new PC with a very fresh system Windows 8.1. On the very first day, I needed to connect to my company through VPN. So I set up a connection, connected without any problem, then wanted to disconnect. But there is just NO WAY to disconn
-
How to replace ws_filename_get function module to file_open_dialog
how to replace ws_filename_get function module to file_open_dialog
-
How to embed custom font (tamil font [ta_IN]) in my android application
We are developing a mobile application (targeting for android & ios) using Adobe Flash Builder 4.6, Adobe AIR 3.5. Requirement is to localize the content for indian languages, and rite now we are targeting tamil locale. We implemented the localizat
-
can i buy my own siri server proxy for my own use ?? if yes from where can i buy one and can i buy it from apple ? please help me quick and thanks
-
PS CC 2014 freeze after startup
Photoshop CC 2014 freezes after startup on MacBook Pro. Start screen dissapears, all tools and panels are loaded and then the app crashes. I tried to reinstall twice but it changed nothing.