File names within a directory
Hello,
I am trying to get a list of all the files in a specific directory for a statistics program.
It would be good if I could get the list back as a string[] or something similar.
I'm using windows and the files are contained in \logs\
This is to allow me to scan all of the files without any user input.
ps. sorry for my lack of english skills
Look at the java.io.File class and at the method list().
Similar Messages
-
Error while reading file name in a directory
Hi,
I am trying to read all the file names within a directory, however I get the below error while running the code.
Run-time error '5':
Invalid procedure call or argument
The actual path is "Q:\Budget\Historical Budgets\FY15\*.xls*"
and ThisWorkbook.Sheets(1).Range("A1").Value = FY15 in my excel sheet.
"Below is the code I am using"
Dim file As Variant
file = Dir("Q:\Budget\Historical Budgets\" & ThisWorkbook.Sheets(1).Range("A1").Value & "\*.xls*")
If file = "" Then
MsgBox "no files"
Exit Sub
Else
' ... else, count the files
x = 0
Do While file <> ""
x = x + 1
file = Dir
<---- I get the error at this line.
Loop
End If
Could you please help me to solve this problem
Regards, HiteshDo you want to generate a list of all files in a folder, in your spreadsheet? If so, please try this sample code?
Option Explicit
Private cnt As Long
Private arfiles
Private level As Long
Sub Folders()
Dim i As Long
Dim sFolder As String
Dim iStart As Long
Dim iEnd As Long
Dim fOutline As Boolean
arfiles = Array()
cnt = -1
level = 1
sFolder = "C:\Users\Excel\Desktop\Coding\Microsoft Excel\Work Samples\"
ReDim arfiles(2, 0)
If sFolder <> "" Then
SelectFiles sFolder
Application.DisplayAlerts = False
On Error Resume Next
Worksheets("Files").Delete
On Error GoTo 0
Application.DisplayAlerts = True
Worksheets.Add.Name = "Files"
With ActiveSheet
For i = LBound(arfiles, 2) To UBound(arfiles, 2)
If arfiles(0, i) = "" Then
If fOutline Then
Rows(iStart + 1 & ":" & iEnd).Rows.Group
End If
With .Cells(i + 1, arfiles(2, i))
.Value = arfiles(1, i)
.Font.Bold = True
End With
iStart = i + 1
iEnd = iStart
fOutline = False
Else
.Hyperlinks.Add Anchor:=.Cells(i + 1, arfiles(2, i)), _
Address:=arfiles(0, i), _
TextToDisplay:=arfiles(1, i)
iEnd = iEnd + 1
fOutline = True
End If
Next
.Columns("A:Z").ColumnWidth = 5
End With
End If
'just in case there is another set to group
If fOutline Then
Rows(iStart + 1 & ":" & iEnd).Rows.Group
End If
Columns("A:Z").ColumnWidth = 5
ActiveSheet.Outline.ShowLevels RowLevels:=1
ActiveWindow.DisplayGridlines = False
End Sub
Sub SelectFiles(Optional sPath As String)
Static FSO As Object
Dim oSubFolder As Object
Dim oFolder As Object
Dim oFile As Object
Dim oFiles As Object
Dim arPath
If FSO Is Nothing Then
Set FSO = CreateObject("Scripting.FileSystemObject")
End If
If sPath = "" Then
sPath = CurDir
End If
arPath = Split(sPath, "\")
cnt = cnt + 1
ReDim Preserve arfiles(2, cnt)
arfiles(0, cnt) = ""
arfiles(1, cnt) = arPath(level - 1)
arfiles(2, cnt) = level
Set oFolder = FSO.GetFolder(sPath)
Set oFiles = oFolder.Files
For Each oFile In oFiles
cnt = cnt + 1
ReDim Preserve arfiles(2, cnt)
arfiles(0, cnt) = oFolder.Path & "\" & oFile.Name
arfiles(1, cnt) = oFile.Name
arfiles(2, cnt) = level + 1
Next oFile
level = level + 1
For Each oSubFolder In oFolder.Subfolders
SelectFiles oSubFolder.Path
Next
level = level - 1
End Sub
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it. -
Allowable Characters in the file names within Oracle iFS
What characters are allowable in file names within Oracle iFS?
Are slashes (/ \) possible?
Thanks,
Sai Mummalaneni.Be carefull with file and directory names in iFS. You might be able to create folders and add document to it through the web interface that the windows explorer interface might not be able to interpret. Like a directory named '.'.
Tamas Szecsy -
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 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 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. -
Listing of all file names in a directory
Hello everyone,
Is there a way to get the listing of all file names in a directory
pointed by an entry in dba_directory in oracle into a collection in
pl/sql procedure.
Thank you.
Tuncaythis is the same problem I am trying to solve now. I found some ehlp in Tom Kyte articles on java stored procedures.
create global temporary table DIR_LIST
( filename varchar2(255) )
on commit delete rows;
create and compile java source named "DirList" as
import java.io.*;
import java.sql.*;
public class DirList
public static void getList(String directory)
throws SQLException
File path = new File( directory );
String[] list = path.list();
String element;
for(int i = 0; i < list.length; i++)
element = list;
#sql { INSERT INTO DIR_LIST (FILENAME)
VALUES (:element) };
create procedure get_dir_list( p_directory in varchar2 )
as language java
name 'DirList.getList( java.lang.String )';
then you call in your pl/sql and fill your collection from the DIR_LIST table:
get_dir_list('the name of the directory' );
---then you fill the collection by fetching the DIR_LIST table
good luck,
Florin -
Load all file names in a directory to a SQL Table
I need to load all the file names in a directory to a SQL table. It must be done via TSQL or SSIS. If using TSQL cannot use xp_cmdshell or any undocumented sprocs. So I am guessing it will be SSIS. But still open to suggestions. I am an SSIS newbie and need
a nudge in the right direction of how to get the file names into a SQL table.
ThanksLet me add a bit of background. We are sent a group of files. Each file has the ccyymmdd date attached to the name. Possible that we miss processing one day and the next day there are two sets of files in the directory. file1_20140101, file2_20140101,
file1_20140102, file2_20140102. I cannot guarantee what the file names will be. Just know that i need to process the 20140101 files in one batch, and then the 20140102 files in the next batch. So thinking that i could read all the file names into a SQL table,
distinct on the date and then sort by the date and pull off those files to process first. Thinking this will be done in SSIS. Open to any ideas or suggestions. -
Unable to convert the file name in Target directory
Dear Experts,
Currently iam facing a problem with some files.my interface is a File to file .As per the interface the sender will pick the flatfiles from source directory which the file name was BNP_NE201.txt once my file reached to target directory the name of the file willrenamed as VENDOR_Payment.NE201 automatically for this they have done some OS level script in receiver communication channel of the first interface which we have added "un operating system command after message processing" in processing parameters tab.again one more sender comm channel wil pick the file from first target directory which is having naming convesion of "VENDOR_Payment.NE201 " and post it to target. all the two interfaces are file to file (NFS) . for a parctuclar day files has been posted to 1 st target directory and the receiver communication channel is not yet convert the file names bcz of that the second communication channel can't able to pick the files from target directory. for some times that is working fine and some times it is unable to convert.
from our side i check every thing .could you please suggest me the way to approch
Reagrs,
Kiran tanuku>> for a parctuclar day files has been posted to 1 st target directory and the receiver communication channel is not yet convert the file names bcz of that the second communication channel can't able to pick the files from target directory. for some times that is working fine and some times it is unable to convert.
You need to wait until the file is converted. After when it is converted then the second interface sender communication channel will pick the files.
What do u mean by unable to convert?
Is it unable to do the content conversion? if so then check the data as you said that it sometimes it works fine.
> The best approach is to change the name of the file in the receiver communciation channel instead of using a script.
Thanks, -
FILE SENDER ADAPTER - TO GET A DINAMIC FILE NAME IN THE DIRECTORY
Hi,
Please help me.
I have to read by a file sender adapter a specific file in the directory that its name is Dyyyymmdd, where yyyymmdd is variable according with the current day:
D - fixed letter
yymmdd - year,month and day of the current day.
I cant´t use D* in the File Name Scheme because I must read only the one file generated in the day.
How can I configure my file sender adapter to read this especific file in the directory?
Thanks in advance.
Mider.Hi Krishna,
I must access only one file by time ( of the current day ), but in the directory I have a lot of them of different dates. I mean, in the of the read ( in the adapter configuration ) , I need to configure the name of the file Dyyyymmdd before of the reading in the directory, in other words, I need to construct the name of file (withe the current date) before the communication channel access the file to read it.
I think that OS command just can be applicated in file receivers, but if possible, at your purpose, how can I access the name of this especific file via OS command for senders?
Thanks,
Mider.
Message was edited by: Midervilson Andrade
Message was edited by: Midervilson Andrade -
File Name and Target Directory name issue in FTP CC
Hi All ,
I am using following code to assing file name and directory name in UDF. I don;t want these parameters to be part of my target structure. Since i have created these files names in UDF, what are the values do i need to mention in FTP CC's "File access Parameter" which are mandatory fiels in CC ?
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create(u201Chttp://sap.com/xi/XI/System/Fileu201D,u201CFileNameu201D);
String myFileName =biz +".dat";
conf.put(key, myFileName);
//Similar code for direcotry
Thanks for your support.
MKHi,
in ID in receiver file comm channel, just tick the option of Adapter Specific messge attributes and in it tick FileName and DirectoryName.............
the filename and directory you give in comm channel will be treated as dummy and the values will be taken from your UDF.......
Regards,
Rajeev Gupta -
File name in different directory
i have a problem when saving files:
I copied all the files from one directory to another ---with the same file name and I tried to make chnages in the new directory, But I found that all the changes I made in the new directory also happened in the old directory. So Labview recogonize file names only, not file paths. I don't like this feature!!!!!This is an old problem with no easy solution as of now. For a better description of what is going on here, you can read this discussion where I answered a similar question a while ago.
Ed
Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences. -
Need to reference file name within the XML Output
Not sure if this is possible, as I'm new to the livecycle/XML world. But I need to be able to reference a file within the XML output from the PDF.
The Scenario is that a pdf form of a business card will be issued to 50 franchisees for them to type in their names and mobiles, click submit and the XML file to be sent to myself, and be imported in to InDesign populating their data ready for printing. Up to here I have it working perfectly.
However as each franchisee have a combination of up to 5 logos to place in the bottom corner to save having to have various templates with different combinations of logos and having to ensure the correct templates are used. I intend to reference each companies combination as an EPS and make the reference within the xml out and have it import directly in with the other data. I can type the code directly within the xml but I would like to have the form reference it directly in the xml output. Is this possible or am expecting to much of livecycle? Any help/advice greatly appreciated.
DavidHi MadhavaGanji,
I have post how to validate the file name, header row against definition table which stored the file name and column definition.
Take a look and see if this is helpful.
http://sqlage.blogspot.com/2013/11/ssis-validate-file-header-against.html
http://sqlage.blogspot.com/ -
How to get JSP file name within a servlet?
I wonder is there any method that we could use to print out the JSP's file name which called a servlet within the servlet itself? For instance, A.jsp called B.class which is a servlet, and when the servlet is being invoked print out "A.jsp" or "A" in a dos screen.
Thanks for any reply.The Referer is an optional HTTP header, and it only exists when a page is called from an hyperlink (i.e. from another web page). The general meaning of Referer is the "caller page". There at least two situations in which there will be no Referer header:
1. When the usuer types in the destination page address directly, or get it from a bookmark/favorite or similar. Since there is no caller page, there would be no Referer.
2. Althought browsers usually send the referal page when you choose a link, some privacy control programs (such as Norton Internet Security etc.) can intercept the request and strip out the Referer header, even when there is a caller page. -
Method to get all File names in a directory
Hallo together,
has Java any method, to get the file names in a specific directory?
Regards,
Martin... or simply list() if you're interested in file names only.
Maybe you are looking for
-
Movie purchased on iPad doesn't show up in iTunes
Hello, I purchased a movie from the iTunes Store using my iPad2. I'm trying to find it in my iTunes on my PC, but it's not there. I recently changed operating systems from Windows Vista to Windows 7, and I'm still muddling thru synching up my music
-
As per my previous question about the Yellow Submarine iBook crashing on my new iPhone 5S. I was advised to delete the book and redowmload it in case my previous version was corrupted. It appears that (as my original iTunes download is stored in the
-
Lightroom 3.6 does not recognize D600
Actually it shows D600 3, seems like it sees neither the NEF card not the jpeg. I understand that it cannot read the NEF.
-
Hello Friends I have a question. can I install SharePoint 2013 on virtual box which has windows server 2012? The virtual box is sitting on a laptop which has only 8 gb of Ram and 500 gb hard disk space. Can I install SharePoint 2013, SQL server and
-
Display property of key field in master block effects detail blk refreshing
Can anyone throw light on why a screen with the detail block in a straightforward master detail block does not refresh correctly unless one of the two key fields in the master block is displayed? The key field did (of course) exist in the master bloc