473,671 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

script only loops once, doesn't filter for no files

There is a problem on this script. If there are no files in the dir
then I get an error. That is why the if
size of ($FILES)>0) test ***** It should sort and do the for each
loop but it ignores that test. I also have the if($claim_file) test
and that doesn't work either. Should I try if is empty($claim_fi le)?
This code also runs through the loop only once even if there are more
than one claim files. Is that because the for each does not need the
while (!feof($clm_fil e)) since it would stop at the last processed
file?

thanks,

##try{

$dir = "../clm_stuff/";
$archive_dir = "../clm_test/";
$bad_dir = "../clm_bad/";

# FOR EACH FILE IN A GIVEN DIRECTORY:

$dir_handle = opendir($dir);
while (false !== ($file = readdir($dir_ha ndle))) {
# OPEN FILE
if(($file!='.') &&($file!='..') &&($file!='.ftp quota')){
$FILES[] = $file;
}
}
#closedir($dir_ handle);

if(sizeof($FILE S)>0){ ***********
sort($FILES);

foreach($FILES as $file){
$clm_file = fopen($dir.$fil e, "r");
print $file."<BR>";

if $clm_file { ****
# FOR EACH LINE:
while (!feof($clm_fil e)) {
# PARSE ACCORDING TO COMMA DELIMITED
Some code that works here!
}

}
}
}
}
Jun 27 '08 #1
2 1067
if you got no files in your directory the variable $FILES is not
definded at all. so you would have to use isset() to check it. But the
better solution would be to add an $FILES = array(); after creating
the dirhandle
Jun 27 '08 #2
JRough wrote:
There is a problem on this script. If there are no files in the dir
then I get an error. That is why the if
size of ($FILES)>0) test ***** It should sort and do the for each
loop but it ignores that test. I also have the if($claim_file) test
and that doesn't work either. Should I try if is empty($claim_fi le)?
This code also runs through the loop only once even if there are more
than one claim files. Is that because the for each does not need the
while (!feof($clm_fil e)) since it would stop at the last processed
file?

thanks,

##try{

$dir = "../clm_stuff/";
$archive_dir = "../clm_test/";
$bad_dir = "../clm_bad/";

# FOR EACH FILE IN A GIVEN DIRECTORY:

$dir_handle = opendir($dir);
while (false !== ($file = readdir($dir_ha ndle))) {
# OPEN FILE
if(($file!='.') &&($file!='..') &&($file!='.ftp quota')){
$FILES[] = $file;
}
}
Use print_r($FILES) at this point and see what's in the array.

--
Curtis
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1239
by: Holger | last post by:
I needed a tool for extracting patches from CVS based on the log messages. I.e. we mark our fixes and features with a "Bugdb XYZ" And sometimes you need to move a fix/feature to another branch or maybe you just want to inspect exactly what changes were related to a specific bugdb issue. Now I've searched hi and low for this and I now it's out there somewhere bleeding obvious - can't imagine I'm the first to have this thought. I just...
9
2390
by: Jerim79 | last post by:
Here it is: <?php if($_SERVER=='POST'){ $Number=$_POST; $Email=$_POST; $Number2=0; $error=0;
4
2085
by: dbee | last post by:
Right. I've got a really, really annoying/difficult/time consuming problem with my development environment. I'm using django to build a web app with paypal integration. My server is hosted remotely, and it is receiving IPN (payment notifications) POST requests from Paypal. I've checked on google and irc and this is my last shot at solving this before I go mad ... :-( The problem is that I can't debug those POST requests. Browser...
1
47446
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
8476
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8820
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7433
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5695
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2810
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.