473,379 Members | 2,890 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,379 software developers and data experts.

search to see if a file exists

ironmonkey69
Can someone help me with a python script that can see if a file exists and to return a number if does or doesn't?
Aug 17 '07 #1
7 2262
ilikepython
844 Expert 512MB
Can someone help me with a python script that can see if a file exists and to return a number if does or doesn't?
Have you seen the os module? Try the os.phat.exists() function.
Aug 17 '07 #2
bartonc
6,596 Expert 4TB
Can someone help me with a python script that can see if a file exists and to return a number if does or doesn't?
Actually in os.path module:
exists( path)

Return True if path refers to an existing path. Returns False for broken symbolic links. On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.
Aug 18 '07 #3
ilikepython
844 Expert 512MB
Actually in os.path module:
Isn't that what the O/P wants? It return true if the path exists or false if it doesn't, right? That's how it works in my computer.
Aug 19 '07 #4
bartonc
6,596 Expert 4TB
Isn't that what the O/P wants? It return true if the path exists or false if it doesn't, right? That's how it works in my computer.
Yep:
Have you seen the os module? Try the os.phat.exists() function.
I was correcting the misspelling and pointing out the fact that os.path is documented separately.
Aug 19 '07 #5
ilikepython
844 Expert 512MB
Yep:I was correcting the misspelling and pointing out the fact that os.path is documented separately.
Oh, ok, I got you .
Aug 19 '07 #6
peruron
11
I've tried to use import os.path and then use "exists", but I get NameError: "NameError: name 'exists' is not defined"

As the path I wrote the file name itself, since it's located as the same directory as the script: exists(FileName)

Does anyone has an idea what is the problem here?
Aug 19 '07 #7
ilikepython
844 Expert 512MB
I've tried to use import os.path and then use "exists", but I get NameError: "NameError: name 'exists' is not defined"

As the path I wrote the file name itself, since it's located as the same directory as the script: exists(FileName)

Does anyone has an idea what is the problem here?
Either do:
Expand|Select|Wrap|Line Numbers
  1. from os.path import exists
  2. exists(FileName);
  3.  
or do:
Expand|Select|Wrap|Line Numbers
  1. import os.path
  2. os.path.exists(FileName)
  3.  
Aug 19 '07 #8

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

Similar topics

20
by: coosa | last post by:
Dear all, I have illustared with code and sample output data my request in thsi post. I simply was expecting some results from my search "amd socket a 32 bit cache 512 dell" that includes a logical...
3
by: jcouse | last post by:
I am trying to find if a string exists in a file. If it doesn’t, it should return a “-1” and I’ll make my decision based on that Here is a sniplet of the text file game name mapp...
1
by: simon | last post by:
hi, I have the directory with files with doc or txt or similar extensions. Now I would like to create a text search (something similar like find text ALT+F7 in windows commander): user inputs...
1
by: Todd Beaulieu | last post by:
I need to determine if a specified path exists, including the case, but .net isn't making this easy. system.io.file.exists is case-insensitive. If I create a fileinfo object in hopes to retrieve...
1
by: vinothg | last post by:
Hi , I have a binary file which contains 30,000 strings of 20 bytes each.I need to search for a string in the file to see whether the particular string exists. The sample code which i wrote...
3
by: Sabine | last post by:
Hi there, I would need your help again. I am using Dev Avish's API function "Search for a file" http://www.mvps.org/access/api/api0006.htm to find a file on my computer which works well. As...
9
by: Lloyd Sheen | last post by:
For all those who don't think that a recursive search of files in folders is a good thing in the Microsoft.VisualBasic.FileIO.FileSystem namespace listen to this. I am reorg my mp3 collection. ...
3
by: mercuryshipzz | last post by:
#!/usr/bin/perl #use strict; use warnings; sub search_pattern { my $file_name = $_;
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. creating a method to search a tree to find the position of node and to return its pointer value basically i...
5
by: moorcroft | last post by:
Hi I have developed an application that people can use to search for planning applications. The way it works is that once search criteria has been selected and submit is hit, the server will save...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.