473,322 Members | 1,523 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,322 software developers and data experts.

error writing to file

63
Hi, i'm trying to write a file with the contents of a directory.
I create an array of files in the directory (@dirs_and_files).
After that I try to write a file "/home/joao/PERLFOLDERTESTE/fff
with the contents of the directory.
The problem is that I get this error:
"error opening file /home/joao/FOLDERTESTE/fff: Ficheiro ou directoria inexistente at direx1 line 17.".
But I'm sure the file exists and I verified the full path with the 'pwd' command.
Can anyone give me some help?
THis is my code:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use File::Util;
  4.  
  5. my($f) = File::Util->new();
  6. my(@dirs_and_files) = $f->list_dir('/home/joao/PERLFOLDER','--files-only');
  7.  
  8. $file = '/home/joao/FOLDERTESTE/fff';
  9.  
  10. foreach $d (@dirs_and_files) {
  11.  
  12. open ('$file') or die "error opening file $file: $!";
  13. print $file $d;
  14. close ($file) or die;
  15.  
  16. }
  17.  
Thanks,

João
Sep 26 '07 #1
3 2345
numberwhun
3,509 Expert Mod 2GB
Hi, i'm trying to write a file with the contents of a directory.
I create an array of files in the directory (@dirs_and_files).
After that I try to write a file "/home/joao/PERLFOLDERTESTE/fff
with the contents of the directory.
The problem is that I get this error:
"error opening file /home/joao/FOLDERTESTE/fff: Ficheiro ou directoria inexistente at direx1 line 17.".
But I'm sure the file exists and I verified the full path with the 'pwd' command.
Can anyone give me some help?
THis is my code:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use File::Util;
  4.  
  5. my($f) = File::Util->new();
  6. my(@dirs_and_files) = $f->list_dir('/home/joao/PERLFOLDER','--files-only');
  7.  
  8. $file = '/home/joao/FOLDERTESTE/fff';
  9.  
  10. foreach $d (@dirs_and_files) {
  11.  
  12. open ('$file') or die "error opening file $file: $!";
  13. print $file $d;
  14. close ($file) or die;
  15.  
  16. }
  17.  
Thanks,

João
I suggest that you read the page for the open function as you are not using it correctly. When using open, you need to specify first the FILEHANDLE that will be used to reference the opened file, but also the file itself (typically with a > for writing or a < for reading from the file preceding it). That page will help you.

Regards,

Jeff
Sep 26 '07 #2
KevinADC
4,059 Expert 2GB
this syntax ain't gonna fly either:

open ('$file')

I guess he skipped the chapter covering strings and scalars
Sep 26 '07 #3
jcor
63
now it's working correctly, thanks a lot for your tips!!
Sep 27 '07 #4

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

Similar topics

0
by: JC | last post by:
I am using Mysql version: 4.0.18-max-log and trying to populate a database from a text file using source option from inside the mysql environment. The population run OK but when creating the...
2
by: GB | last post by:
Hi Everybody! I have 2 different processes/application. One is writing to a file and another is reading from it. For some reason the code doesnt seems to work and gives mscorlib.dll IOException...
0
by: Kevin | last post by:
I'm writing a service in VB.NET. Reference the following code: Dim oStreamWriter As StreamWriter .... .... .... oStreamWriter = File.CreateText(TempLogFile) If Err.Number <> 0 Then...
5
by: ZWeng | last post by:
I created a windows service using FileSystemWatcher to moniter a folder for file drops. The service uses FileStream and StreamReader to read and process the file. After it is done, the file is...
2
by: smith4894 | last post by:
{ not sure you're aware of that but there are the newsgroups for all major operating systems. you might want to try asking in the forum 'comp.os.linux.development.apps', since memory-mapped files...
4
by: floppyzedolfin | last post by:
Hello! I'm actually encoding an encryption / decryption program. The encryption programes takes a file path in parameter, and encrypts the contents of the file and stores that into another file. ...
6
by: tgnelson85 | last post by:
Hello, C question here (running on Linux, though there should be no platform specific code). After reading through a few examples, and following one in a book, for linked lists i thought i would...
4
by: radhikams | last post by:
hi I have written a code for writing the data of a column from database into a file and again reading that file and displaying. Im writing into an .html file....Now the problem is im...
1
by: cnivas | last post by:
Hi, I'm doing a small project on Python using MySQL as Database in MAC OS X. I was unable to connect the database. I was downloaded MySQLdb from sourceforge.net and I also modified setup_posix.py....
0
Guido Geurs
by: Guido Geurs | last post by:
I'm writing a program that list the contents of a CDrom and also the contents of the ZIP files. When there is a bad Zip file on the CD, the program keeps traying to reed the file and after +- 50...
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...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.