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

Checking to see if file exsists

I've looked around a bit already and from what I'm seeing, I'm doing it right but for whatever reason I'm not getting a true response even though the file does exist.

Expand|Select|Wrap|Line Numbers
  1. print "Enter file name: ";
  2. my $fileName = <>;
  3. my $editedFileName = '~/'.$fileName;
  4. print "File set to: $editedFileName";
  5. chomp($editedFileName);
  6. if(-e $editedFileName){
  7.     print "File exists! Would you like to load the file? \n";
  8. }
  9. else{
  10.     print "File does not exist.\n";
  11. }
  12.  
Jan 30 '09 #1
3 1513
KevinADC
4,059 Expert 2GB
You need to use the full path to the file or be in the directory where the file is stored. The '~' symbol has no meaning in perl in that context.
Jan 30 '09 #2
Hey thanks so much! With that information I was able to figure out a solution.

Expand|Select|Wrap|Line Numbers
  1. print "Enter file name: ";
  2. my $editedFileName;
  3. my $currentWorkingDirectory;
  4. my $fileName = <>;
  5. &setFileName($fileName);
  6. &checkFileExistence($editedFileName);
  7.  
  8. sub setFileName
  9. {
  10.     $currentWorkingDirectory = getcwd;
  11.     $editedFileName = $currentWorkingDirectory."/".$fileName;
  12.     print "File set to: $editedFileName";
  13.     chomp($editedFileName);
  14. }
  15.  
  16. sub checkFileExistence
  17. {
  18.     if(-e $editedFileName)
  19.     {
  20.         print "File exists! Would you like to load the file? \n";
  21.     }
  22.     else
  23.     {
  24.         print "File does not exist.\n";
  25.     }
  26. }
  27.  
  28.  
Jan 31 '09 #3
KevinADC
4,059 Expert 2GB
Very good :)
Jan 31 '09 #4

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

Similar topics

5
by: Tongu? Yumruk | last post by:
I have a little proposal about type checking in python. I'll be glad if you read and comment on it. Sorry for my bad english (I'm not a native English speaker) A Little Stricter Typing in Python...
1
by: Christina | last post by:
How can I do a simple asp check to verify if a physical file exsists on the server or not? Christina
6
by: RoSsIaCrIiLoIA | last post by:
Do you know how to write a self-checking program in standard C? Do I can think that if I write in a file.c static g="1234567"; in the file.exe (or file) there is in some place...
1
by: Harry | last post by:
Hi, just getting started on ASP.NET and C# and MS-SQL. Ive managed to get all the connections working and database intergrated nicely for content and stuff. I now want to include a user...
8
by: Brendan | last post by:
There must be an easy way to do this: For classes that contain very simple data tables, I like to do something like this: class Things(Object): def __init__(self, x, y, z): #assert that x,...
1
by: halcyon943 | last post by:
have 4 folders that I watch and need to move files from to another location. Three constraints: -Finish time. Make sure the program stops transferring files at a specific time -Number of...
1
by: johnd60 | last post by:
Hi there, First-time poster but long-time lurker. I've been working on an application in VB.NET which will serve as a web-installer on a client machine, looking locally for files on a list...
4
by: winningElevent | last post by:
Hi everyone, I have a question would like to ask. So far I know how to retrieve files from device, but sometimes device takes so long to produce file so I want my desktop to keep checking every...
1
by: chanshaw | last post by:
Hey I'm trying to see if a file exsists but I'm using windows, I know in Linux you can use -e but that doesn't seem to work for me in windows. if (-e $filename) { print "File Doesn't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.