473,804 Members | 2,959 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checking for when a file or folder exists, typing problems?

Hi
I have a little program that is importing from os.path import exists, join,
isdir, normpath, isfile
at one point in my program I check if a file exists using
if exists("c:\proj ects"):

and that works fine.

If I change it to be
if exists(thepath) :
where thepath is a commandline argument it does not work fine.

Note that the commandline is c:\projects and when I print thepath to check what
is going on it prints
c:\projects

The only thing I can assume is that there is some sort of typing problem going
on here, but then it should go ahead and give an error then if it's getting
something unexpected obviously.

Any help on what this error is?

Thanks
--
Bryan Rasmussen

Jul 19 '05 #1
2 4250
Hi Bryan,

Here's a potential idea. Try converting the variable to a string by
using the following syntax:
thePath = str(thePathArg)
This will convert the current variable type to a string, which follows
the data type syntax that you have specified at the beginning of your
message.

Hope this helps,

Brian :-)
---
Bryan Rasmussen wrote:
Hi
I have a little program that is importing from os.path import exists, join,
isdir, normpath, isfile
at one point in my program I check if a file exists using
if exists("c:\proj ects"):

and that works fine.

If I change it to be
if exists(thepath) :
where thepath is a commandline argument it does not work fine.

Note that the commandline is c:\projects and when I print thepath to check what
is going on it prints
c:\projects

The only thing I can assume is that there is some sort of typing problem going
on here, but then it should go ahead and give an error then if it's getting
something unexpected obviously.

Any help on what this error is?

Thanks

Jul 19 '05 #2
Bryan Rasmussen wrote:
... at one point in my program I check if a file exists using
if exists("c:\proj ects"):


You should not be using a backslash in non-raw-string source to
mean anything but "escape the next character." The above should
either be written as:
if exists(r"c:\pro jects"):
or:
if exists("c:\\pro jects"):

I suspect you problem has to do with this difference, but perhaps not.
Give exact short code that actually demonstrates the problem.

--Scott David Daniels
Sc***********@A cm.Org
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2866
by: Rob Meade | last post by:
Hi all, I am allowing a user to create a directory within my application. I have them entering the name for the directory in a form. When the form is processed I initially check for any special characters that are not allowed (Windows based server incidently), from here I then need to check to see whether the folder name has already been used (either by a previous entry using the application etc, or reserved names as such ie, /images...
11
16846
by: Daz | last post by:
Would anyone know of a way to check whether or not a particular path is a directory? If I have to go down the route of using _findfirst and _findnext (windows specific), then so be it. However, I don't think it should be that difficult to check. My original idea was to check to see if the path can be opened with fstream, but this can give false results if the path is a filename, and the file cannot be opened. I am using boost, and can't...
2
6898
by: Argonath | last post by:
Hi, I'm afraid this will no doubt horrendously basic as I'm a complete newbie to VB and have dived in without learning to do much... Start in the deep end and all. So if anyone could help, I'd appreciate it; I've got this bit of code and I couldn't for the life of me tell you why it doesn't work, if anyone else can I'd appreciate it! Cheers
1
1919
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 files transferred. Can only move a certain amount of files per time period. -Folders have a priority. The files have to be moved based on the folder priority.
42
2814
by: =?Utf-8?B?UGxheWE=?= | last post by:
I have an if statement that isn't working correctly and I was wondering how I check for a blank string. My Code Example if me.fieldname(arrayIndex) = "" then ----- end if When I do this and there is no characters in the variable it does not enter my IF statement like I would think it should. How do I properly check for a
2
2604
by: patelxxx | last post by:
Checking the folder before actually creating the new folder . Can someone guide me in what 'Checks' do I need to do before I create a new folder? I know that one of the checks will be to see if the file already exists or not. What other checks could I do? See coding for Creating new folder use CGI; use strict; use warnings;
1
2075
by: rogersmithiii | last post by:
We have a production web site - www.thesite.com - laid out as follows on IIS 6: d:\Inetpub\wwwroot\default.asp There are lots of subdirectories inside of WWWROOT including a cgi-bin directory that contains a simple ASP Visitor Counter script. This cgi-bin directory sits at D:\InetPub\wwwroot\cgi-bin\filename.ext We also have a staging site (for testing web content before posting to the real site) located here.
4
1674
by: mikkoO8 | last post by:
hi. im actually making a desktop cleaner that can move the files and icons to a folder inside the listview box. i can make the listview box filled with files contains at the desktop and i can make a new folder which suppose to be move the files on that folder i have 3 problems: 1. is how to get last access time of the FILE and put it column2 of the listview 2. i want to view that are unused icon and document last week, 2weeks, 1month...
8
12235
by: Sweetiecakes | last post by:
In our series of "probably something simple"... I am doing a File.Exists operation to check if a file exists. Let's assume that this file is C:/test.txt. Now, if I do File.Exists("C:\\Test.txt"), I do not want it to tell me that the file exists - this is a check for a File.Move operation (some file renaming functionality). But if I check C:\\test.txt, it should return true.
0
9571
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6845
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
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 we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.