473,511 Members | 16,846 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_file)?
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_file)) 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_handle))) {
# OPEN FILE
if(($file!='.')&&($file!='..')&&($file!='.ftpquota ')){
$FILES[] = $file;
}
}
#closedir($dir_handle);

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

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

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

}
}
}
}
Jun 27 '08 #1
2 1063
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_file)?
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_file)) 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_handle))) {
# OPEN FILE
if(($file!='.')&&($file!='..')&&($file!='.ftpquota ')){
$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
1235
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...
9
2372
by: Jerim79 | last post by:
Here it is: <?php if($_SERVER=='POST'){ $Number=$_POST; $Email=$_POST; $Number2=0; $error=0;
4
2077
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...
1
47354
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...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7423
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...
1
7081
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...
0
7510
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...
0
5668
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,...
1
5066
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
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...
0
1576
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 ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.