Checking for a file in a dir + all subdir's
i'm checking if a file exists in C:/, and all sub directories of C:/. It's easy enough to scan for it in the parent directory, but how would i go about checking all the sub directories also? I couldn't get a system of using the boolean isDirectory working, here's what I have though:
import java.io.File.*;
import java.io.*;
class Readit {
File file;
Readit(String fileName) {
file = new File(fileName);
check(file);
void check(File file) {
try {
if(file.exists()) {
String files[] = file.list();
for(int i = 0; i < files.length; i++) {
System.out.println(files);
File subdir = new File(files[i]);
if(subdir.isDirectory()) {
String infil[] = subdir.list();
}{color}
} catch(NullPointerException nul) {}
public static void main(String[] args) {
Readit r = new Readit(args[0]);
}Edited by: Pattylulz on Jun 10, 2008 8:43 PM
It is not clear what exactly you need.
I assume that you want to find recursively a file/folder with given name:
private static final FileSystemView fsv =
FileSystemView.getFileSystemView();
private static final File checkFile(File pathParent,
String name) {
final File[] list = pathParent.listFiles();
if (null == list)
return null;
File pathFound = null;
for (int i = 0; i < list.length && null == pathFound; i++) {
final File pathCur = list;
// Can use system display name or name (pathCur.getName())
final String nameCur = fsv.getSystemDisplayName(pathCur);
// If you need to search only files, use: pathCur.isFile()
if (name.equalsIgnoreCase(nameCur)) {// or equals
pathFound = pathCur;
} else {
// All traversable items, but skip links to folders
boolean isLink = false;
try {
isLink = ShellFolder.getShellFolder(pathCur).isLink();
} catch (FileNotFoundException e) {
if (fsv.isTraversable(pathCur) && false == isLink) {
// Recursive is subfolders
pathFound = checkFile(pathCur, name);
return pathFound;
public static void main(String[] args) {
File file = checkFile(new File("C:\\"), args[0]);
if (null != file)
System.out.println("File is found: " + file);
else
System.err.println("Cannot find file with name: " + args[0]);
Mimo
Similar Messages
-
I'm running Vista for operating system on an HP laptop that's about 2 years old. I've installed all current updates.
I've always used Firefox. It started crashing and creating processes but not launching. Went to support and scoped it out -- there was a lock file my profile directory. I deleted it, and Firefox started loading.
Used it a few times -- closed the app each time on exist as per suggestions on support site info. One time -- back to square one, wouldn't load, just created a process. Reboot, ending process, checking for lock file, reinstalling -- all unsucessful.Brian
Below is from using a SIP build. It does offer G722, but it's way down on the list so it's never used...
m=audio 32678 RTP/AVP 0 8 18 102 9 116 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:102 L16/16000
a=rtpmap:9 G722/8000
a=rtpmap:116 iLBC/8000
a=fmtp:116 mode=20
a=rtpmap:101 telephone-event/8000
Taking Sreekanth's suggestion to try a Skinny build, I get the following when I make a call. It offers codecs in the order I SET THEM AND ONLY THE CODECS I SET! YAY!
m=audio 19374 RTP/AVP 9 0 101
a=rtpmap:9 G722/8000
a=fmtp:9 bitrate=64
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
Using a Skinny build on the phones also solved other issues. The phones use G711 when the whole path supports G711 and G722 when the whole path supports G722. It doesn't always use G722 and rely on transcoding for the call paths that can't use it. It's fantastic.. The phones also receive the QoS tagging that I set and that seems to result in better audio quality than on the SIP builds, which never did get those settings. Finally, it even solved a slow Exchange 2013 answer issue I have been experiencing for quite some time. I practically fell out of my chair when I saw everything that was fixed just by switching...
Cisco, PLEASE FIX YOUR SIP BUILDS! It's insane how the SCCP builds work perfectly and the SIP builds don't, especially with how much these phones cost.. I was thinking of possibly acquiring some 9951s, which are SIP only. I'm a little leery about that at this point. If they have the same kinds of issues as the SIP builds for the 7975g, there's no SCCP alternative to use..
Sreekanth
Thank you for suggesting a Skinny build.. That was about the only thing I didn't try. I am happy beyond belief that this is working so well now, even though the SIP builds should be just as well developed as the SCCP ones. -
File Handling (Check for existing file)
now my problems is that i need to have a code that upon a request checks for a file (in the home dir) and if the file exists reads the information and ouputs it. here is an example:
check if file TEST.DATA exists?
check approved TEST.DATA exists
information outputed...
if the file is missing i need to have an error message...
PS. sorry if the question falls under "lame" but i am fairly new to java and i dont know the commands that well... thank you in advance!File.exists()
Reading Text from a File
Useful places to seek for information:
- Java API documentation
- The Java Tutorial
- Code examples from Java developpers Almanac
- Google
- ... -
Hi all, I have a script which returns the path for a file in this way:
set outfile to (choose file name with prompt "Choose output file." default name "out.iso")'s POSIX path
the path is then passed to the shell. Now, I want the script to check whether that file exists and if it does, the script needs to be stopped.
I tried some ways I found on the web but none seems to work.
Any help would be appreciated.
Thank you!
LorenzoTry using:
set outfile to (choose file name with prompt "Choose output file." default name "out.iso")'s POSIX path
set thefile to POSIX file outfile
tell application "Finder"
if exists thefile then
return --or other commands to stop script
end if
end tell
(57077) -
Hi
Is there a way for checking the availability of a file in the sender system folder in PI 7.0?hi
if you done all these desingn and configuring part
copy the xml format file and paste in to the source file in your woek space
then check the Runtime workBench
in that check the component monitoring
in that check the communication
and check your sender file is going to the XI or not. if it is green then it is send atherwise having the problem
check
thanks
Regards
vijay -
Need script to check for duplicate file names when copying a folder
Hello,
I am a new applescript user trying to write what I believe should be a simple script. I was planning on using the "add-new item alert" script as a template.
Basically I have people copying folders of photos into a library folder, but I don't want the Finder to copy the photo if it already exists in the library. The images in the library are organized into subfolders.
I need a script that will check all the file names in the new folder against all the file names in the library, and NOT add the new one if it already exists.
If anyone can help it would be greatly appreciated,
Thanks,
CI have a script that "kind of" works. The only problem I've seen is that it gets confused when filenames contain characters that are fine in Macland but not good in Unixland. Forward slashes are a good example of this.
In this case I have a folder in my home named "copytest" Inside copytest are two folders:
Source (containing the images to be added)
Dest (My existing library of images)
It also assumes that the folder of images to be added contains no sub-folders. Hope this helps.
tell application "Finder"
set theSource to folder "source" of folder "copytest" of home
set imagesToBeCopied to name of every file of theSource
end tell
repeat with theFile in imagesToBeCopied
try
if (do shell script "find -r ~/copytest/dest -name " & quoted form of (theFile as string)) is not equal to "" then
--The file exists. Don't copy it
else
--the file doesn't already exist. Copy it.
end if
on error
return "Failed while trying to check for existence of a file"
end try
end repeat -
PL SQL block - Check for empty file
Hello,
I need help in writing pl sql code to check a file to verify if it has 0 records (file size = zero kb.) In a preceding pl sql block, I am performing a SELECT on data and writing it to a file. If that file is empty/has no records, then I would like to stop the process from continuing on to my next pl sql block which performs an update function.
Summary:
1) Create file from SELECT
2) Check file for zero data, if true, trigger error, if false, continue to next pl sql block.
3) Run update on records if data exists in the file.
Thanks in advance!Thanks John,
You've been of great help so far and a really appreciate it. I'm so close to getting this, I just need help with how to create an error when the file shows no data. I will be running this as an Oracle Apps Concurrent request. I'd like for the job to end in error when no data exists for the file. In unix, I can enter "EXIT 1" and it signals to the concurrent manager to put end the job with an error status. How can I do something similar using pl sql? Here is my code so far, with the missing piece. Thanks!
DECLARE
vFile UTL_FILE.FILE_TYPE;
vrecs BOOLEAN := FALSE;
vnodata EXCEPTION;
BEGIN
vFile := UTL_FILE.FOPEN('/devlop, 'norecs.txt', 'w', 32767);
FOR x IN (
SELECT
node_name AS txt
FROM
applsys.fnd_nodes
WHERE
node_name = 'blahblahblah'
LOOP
vrecs := TRUE;
UTL_FILE.PUT_LINE (vFile, x.txt);
END LOOP;
UTL_FILE.FCLOSE(vFile);
IF NOT vrecs THEN
RAISE vnodata;
END IF;
EXCEPTION
WHEN vnodata THEN
*<what can I put here to cause the pl sql block to error???>*
END;
/ -
Hi,
My requirement is as below:
In source FTP directory, I have to check if source file exists or not. If exists, that file shuld be picked up and created at target side with header, line items and detail record.
If the file does not exist, then a file should be created at target side with only header and detail record with no line item records.
In any case, a file should be created at target side.
Please suggest if Dynamic configuration is the better option for this or any other way gives better results.
Thanks and Regards,
Anil.@ Babu,
The query is like...
If the file does not exist, then a file should be created at target side with only header and detail record with no line item records.
In any case, a file should be created at target side.
so i answered as,
Now when the file is not present, u will get only the empty tags..(message type name in XML Payload)
If you read the question carefully, it is not being asked "how to handle empty files". It is about "what to do if there are no files in the source directory", which implies that if there are no files present, then create one.
u said as,
This option won't "create" an empty file.
Correct me if i am wrong, DID I SAY IT WILL CREATE an EMPTY FILE IN SOURCE FOLDER???
No, you don't need to say that .. it was evident from your answer. In this forum post, nothing is being asked regarding empty files, so please don't provide such answers which has nothing to do in this situation.
-- Abhi -
Check for Duplicate files.
I have multiple folders with duplicate files, i was wondering what is the best way to check for duplication based on file content even if the file name is slightly different.
There are several commercial software options. I suggest that you use the ones that use SHA1 matching.
Decloner is pretty good, and it comes with a 30-day trial that is FULL FEATURED.
http://www.pixelespressoapps.com/decloner/
Only works on snow leopard and up.
Their website conviniently compares other duplicate file software packages.
I purchased Twins, which is also great.
http://www.rockysandstudio.com/apps/twins
Only works on Lion and up.
Remember, SHA1 is the way to go if you want to find duplicates with highest accuracy. -
Hi,
I created a thread that "scans" a given folder for files. If any file is found then i move that file to another location, the problem arises if i have one application(example: Microsoft Word) saving the files there, and the thread "grabs" the file, before the process of saving is completed.
How do i solve the problem? I thought in checking if the file is open, then the thread should touch it, but how do i check if the file is open or closed?
Thanks in Advance,
MrNiceLifeThe claim has been made that "NIO" in jdk 1.4.x gives methods for dealing with this problem.
-
Check for updated file in physical drive and if exists then call procedure?
hi
i want to check on local drive in 1 folder if upated file is there and then start my batch process which will load data from that file.
so how to check if that file is present in location and its upated one
is there any utiliy in oracle ????
Reply ASAPUse UTL_FILE.FOPEN function with 'r' mode (read text mode). If it fails, then the file does not exist.
-
Text_io checking for the file exists?
When using TEXT_IO package procedures within a form, How can I check whether the file with the same name exits in the same file path?. I mean what is the text_io procedure? Is there any thing specific?
something like
EXCEPTION
when OTHERS then
if SQLCODE = -302000 then -- file problems
MSGBOX('Error: File could not be opened.');
raise FORM_TRIGGER_FAILURE;
else
MSGBOX('Error: ' || SQLERRM);
raise FORM_TRIGGER_FAILURE;
end if; -
Hi Guys,
I was hoping someone could help me with a PowerShell script to check a directory to see if any .ost files exist.
If it detects any .ost files I want it to run this code:
get-childitem "C:\Users\*" -include *.ost -recurse -force | foreach-object { remove-item $_ -force }
If it doesn't detect any .ost files I just want the script to exit.
Looking to add this to our startup scripts in group policy
Many thanks,Hi Tlewis4435,
In addition, please refer to the script below:
$files = get-childitem "D:\SHARE\*" -include *.ost -recurse -force
if($files){ #detect files
foreach($f in $files) { remove-item $f -force }
else{exit} #if there is no file then exit powershell
If there is anything else regarding this issue, please feel free to post back.
If you have any feedback on our support, please click here.
Best Regards,
Anna Wang
TechNet Community Support -
How can I check for corrupt files/ programs?
I have just received a call from a scammer, but before I realised it wasn't real, they logged on to my Mac (using TeamViewer) and had control for about five minutes. At best, they were just trying to hard-sell me some anti-virus protection, but I'm worried it's much worse than that.
Once I suspected something, I instantly cut the connection and shut down the Mac, but I'm worried that they may have placed some programs on my Mac to either send information/ files or just to track internet key strokes.
Apart from the obvious (speaking to my bank, etc.), is there something I can run on the Mac to see if it is clean?
Urgent help appreciated.The only way you can be sure that the computer is not compromised is to erase at least the startup volume and restore it to something like the status quo ante. The easiest approach is to recover your entire system from a backup that predates the attack. Obviously, that's only practical if you know when the attack took place, and it was recent, and you have such a backup. You will lose all changes to your data, such as email, that were made after the time of the snapshot. Some of those changes can be restored from a later backup.
If you don't know when the attack happened, or if it was too long ago for a complete rollback to be feasible, then you should erase and install OS X. If you don't already have at least two complete, independent backups of your data, then you must make them first. One backup is not enough to be safe.
When you reboot after the installation, you'll be prompted to go through the initial setup process for a new computer. That’s when you transfer the data from one of your backups in Setup Assistant.
Select only users in the Setup Assistant dialog — not Applications, Other files and folders, or Computer & Network Settings. Don't transfer the Guest account, if it was enabled.
Reinstall your third-party software from original media or fresh downloads — not from a backup, which may be contaminated.
Unless you were the target of an improbably sophisticated attack, this procedure will leave you with a clean system. If you have reason to think that you were the target of a sophisticated attack, then you need expert help.
That being done, change all Internet passwords and check all financial accounts for unauthorized transactions. Do this after your system has been secured, not before. -
Adadmin error when run check for missing files
Hi All,
When i run adamin for checking missing flie option it return the error
Unable to verify files for iSupplier Portal.
AD Administration error:
The following file is missing:
/m01/TEST/apps/apps_st/appl/pos/12.0.0/admin/driver/posfile.drv
My EBS version is :R12.1.3
when i checked files existed in $POS_TOP there are only three subdirectories available i.e. log mesg out
when i checked in one of the older server in mean R12.1.1 all files existed in POS_TOP i.e. admin help html java log mds media mesg out patch sql xml
Can i copy all the files from old server(12.1.1) to produciton(R12.1.3)
Due to this error JAR files cannot be generated
Thanks
AligWas this 12.1.3 instance upgraded from the same copy of 12.1.1 instance you have?
Can i copy all the files from old server(12.1.1) to produciton(R12.1.3) They are different releases. However, you could try copying the files and see if this helps. Are you using this product?
Due to this error JAR files cannot be generatedWhat is the error? Copy the missing files/directories for now and check then.
Thanks,
Hussein
Maybe you are looking for
-
Capture settings for Canon XL2 shot in: 16:9 24p 2:3:3:2
I just boght the XL2 and FCP, and need to capture a four hour interview I shot today in 16:9 24p 2:3:3:2. I just don't know how to set up the capture settings correctly. Thanks guys, Wes iMac G5 Mac OS X (10.4.7) 2.0 GHz, 400Gb Hard Drive, 2Gb Ra
-
Is there a way to escalate an issue at Apple?
I'm trying to get through to a manager or supervisor at Apple, to no avail. Does anyone know of an escalation process? Searched the Internet, lots of people asking the question, Apple appears to be stonewalling us all. I've had problems with my MacBo
-
Hi all, I upgraded whole system and xorg 1.6.1 got installed...now it wont let me configure it!!! which is so lame I mean I am not sure if everything changed in the way we used to configure X - by modifying /etc/X11/xorg.conf but now there is no such
-
Hello, I need to convert a UTC timestamp in the long form in the local version (CET) but if I use the CONVERT function I lose the decimal part (it becomes 0000000). Any idea? Thanks in advance. Angelo
-
Apache in front of OC4J? AJP13?
Hello, I need to place OC4J behind Apache. I have a working Apache setup that talks to JBoss/Jetty via AJP13 on port 8009. How can I configure OC4J to listed to some port and listen for AJP13 requests? Does OC4J come with its own protocol and Apache