473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

File Directory

Okay I'm back again,
I have a list of files in a directory. i am starting at the top of the list and when i'm down with that first file, i am deleting it by using 'unlink'. and then i want to move on to the next file that is at the top of the list.

how do i select that first file (regardless of what the file name is) and save that file name into a variable?

Terra
Dec 5 '07 #1
5 1163
numberwhun
3,509 Expert Mod 2GB
Okay I'm back again,
I have a list of files in a directory. i am starting at the top of the list and when i'm down with that first file, i am deleting it by using 'unlink'. and then i want to move on to the next file that is at the top of the list.

how do i select that first file (regardless of what the file name is) and save that file name into a variable?

Terra
First, can you please post your code? We want to see how you are trying to do this.

Once we know what you are trying, we can then make the necessary suggestions.

Regards,

Jeff
Dec 5 '07 #2
Well, there not much code to post. i have a directory that has more than one file in it and i would like to just pick the first one. My code saves files into the $destination_dir folder and from this directory i want to select the first one without using the file name.

For example, the directory itself would have the file names
test_results0001.txt
test_results0002.txt
test_results0003.txt

once i unlink the test_results0001.txt then the 0002 is now the first one.
test_results0002.txt
test_results0003.txt

when i'm done with that one, i will unlink it and move to the next one. but i don't know how to grab it to use it. so you can see why i can't go by the file name.
[HTML]
$destination_dir = C:\\Test Data\\Test_Results\\";
.
.
.
@result_files = <'$destination_dir\\ '>; #this is where i don't know how to call it

foreach $file (@result_files)
{open (RESULT, "<$file") or die "and error occurred: $!";}[/HTML]
Dec 5 '07 #3
numberwhun
3,509 Expert Mod 2GB
Well, there not much code to post. i have a directory that has more than one file in it and i would like to just pick the first one. My code saves files into the $destination_dir folder and from this directory i want to select the first one without using the file name.

For example, the directory itself would have the file names
test_results0001.txt
test_results0002.txt
test_results0003.txt

once i unlink the test_results0001.txt then the 0002 is now the first one.
test_results0002.txt
test_results0003.txt

when i'm done with that one, i will unlink it and move to the next one. but i don't know how to grab it to use it. so you can see why i can't go by the file name.
[HTML]
$destination_dir = C:\\Test Data\\Test_Results\\";
.
.
.
@result_files = <'$destination_dir\\ '>; #this is where i don't know how to call it

foreach $file (@result_files)
{open (RESULT, "<$file") or die "and error occurred: $!";}[/HTML]
Ok, let me see if I understand this. You have a directory that has "x" number of files in it. You want to get a list of the files in that directory an delete them, regardless of the file name? Is that correct? It looks like you want to open each file, individually and do something with the contents and then delete it.

Can you just clarify for me?

As for the line above you "don't know how to call it", is that the line you are getting the list of files and plugging them into an array?

Regards,

Jeff
Dec 5 '07 #4
I'm sorry, that foreach loop shouldn't be there. it should be:

Expand|Select|Wrap|Line Numbers
  1. $result_files = <'destination_dir\\...'>;
  2.  
  3. open (RESULT, "<$result_files");
And you just made me see what my error is. i think i have the solution!

Thanks!
Dec 5 '07 #5
numberwhun
3,509 Expert Mod 2GB
I'm sorry, that foreach loop shouldn't be there. it should be:

Expand|Select|Wrap|Line Numbers
  1. $result_files = <'destination_dir\\...>;
  2.  
  3. open (RESULT, "<$result_files");
And you just made me see what my error is. i think i have the solution!

Thanks!
Ok, then I await your new code. :-)

Regards,

Jeff
Dec 5 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
5
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up...
2
by: Jack David | last post by:
Using the code below I am able to monitor a single directory for a new file and then kick-off a process to deal with the file. The question is??? How would I modify this code to be able to monitor...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
4
by: tasahmed | last post by:
Hello Friends, I wrote a function which scans the current working directory and lists out details such as directory/file owner, permission etc. The output of this script can be viewing in the...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.