473,761 Members | 4,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: problems with opening files due to file's path


Gerhard Häring wrote:

Alexnb wrote:
>Okay, so what I want my program to do it open a file, a music file in
specific, and for this we will say it is an .mp3. Well, I am using the
system() command from the os class. [...]

system("\"C:\D ocuments and Settings\Alex\M y Documents\My
Music\Rhapsody \Bryanbros\Weez er\(2001)\04 - Island In The Sun.wma\"")
[...]
Try os.startfile() instead. It should work better.

-- Gerhard

--
http://mail.python.org/mailman/listinfo/python-list

No, it didn't work, but it gave me some interesting feedback when I ran it
in the shell. Heres what it told me:
>>os.startfile( "C:\Documen ts and Settings\Alex\M y Documents\My
Music\Rhapsod y\Bryanbros\Jas on Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")
Traceback (most recent call last):
File "<pyshell#1 0>", line 1, in <module>
os.startfile("C :\Documents and Settings\Alex\M y Documents\My
Music\Rhapsody\ Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm Yours.wma")

WindowsError: [Error 2] The system cannot find the file specified:
"C:\\Docume nts and Settings\\Alex\ \My Documents\\My
Music\\Rhapsody \\Bryanbros\\Ja son Mraz\\I'm Yours (Single)\x01 - I'm
Yours.wma"

See it made each backslash into two, and the one by the parenthesis and the
0 turned into an x....
--
View this message in context: http://www.nabble.com/problems-with-...p17759825.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08
34 5367
Alexnb wrote:
I don't get why yall are being so rude about this.
We're frustrated with your apparent inability to understand anything
we're saying.
My problem is this; the
path, as a variable conflicts with other characters in the path, creating
escape characters I don't want, so I need a way to send the string to the
os.startfile() in raw, or, with all the backslashes doubled.
No, no, no, no, NO! That is not your problem! You are drawing unfounded
conclusions from the fact that you had to double up backslashes when the
filename came from a string literal. The situation is entirely different
when the filename comes from user input. No doubling up of backslashes
is necessary when the filename comes from user input. TRUST ME!

For simplicity, start with this code to convince yourself:

import os
filename = raw_input("Plea se enter a filename: ")
os.startfile(fi lename)

Once you get that to work, replace raw_input with a function that gets
the filename from your GUI.

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 27 '08 #31

Well, I don't understand why I don't need to change anything because say I
run that code, which goes straight from the entry box to the startfile()
function. It doesn't work with some of the paths, that is the whole problem.
the problem is when I enter a path with those certain characters next to
each other. Everyone seems like there is some huge thing that I am
missing... and I don't know what it is, because when I run that code, with
that path I was talking about, I get an error, and it shows me that it is
because of the \0.
Jerry Hill wrote:
>
On Wed, Jun 11, 2008 at 4:16 PM, Alexnb <al********@gma il.comwrote:
>>
I posted the underlying code, but I haven't made the GUI code because if
I
can't get the underlying code right it doesn't matter, well in my eyes it
doesn't but I am probably wrong. But it will look somehting like this:

What you're missing is that all of the problems you're having with
escape characters *only apply to string literals inside your python
source code.* If you're getting the string from the console, you
don't need to escape or change anything. If you're getting the string
from a Tk text box, you don't need to escape or change anything. If
you're getting the string from the filesystem, you don't need to
escape or change anything.

The only place you have to be careful is when you type out a literal
string inside your .py source code. When you do that, you need to
properly escape backslashes, either by putting them in raw strings, or
by doubling up your backslashes.

If you haven't already, reread the section of the python tutorial
about string literals: http://docs.python.org/tut/node5.html.

--
Jerry
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context: http://www.nabble.com/problems-with-...p17787168.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #32
Alexnb wrote:
Okay, so I wrote some code of basically what I will be doing, only with
exactly what I need for this part of the program but here you go: [...]
Finally...
path = "\"" + path + "\""
That line of code is unnecessary. Delete it.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 27 '08 #33

Haha, okay well sorry that I was being so stupid, but I get it now and I
apoligize for causing you all the frustration. But I did get it to work
finally.
Carsten Haese-2 wrote:
>
Alexnb wrote:
>I don't get why yall are being so rude about this.

We're frustrated with your apparent inability to understand anything
we're saying.
>My problem is this; the
path, as a variable conflicts with other characters in the path, creating
escape characters I don't want, so I need a way to send the string to the
os.startfile () in raw, or, with all the backslashes doubled.

No, no, no, no, NO! That is not your problem! You are drawing unfounded
conclusions from the fact that you had to double up backslashes when the
filename came from a string literal. The situation is entirely different
when the filename comes from user input. No doubling up of backslashes
is necessary when the filename comes from user input. TRUST ME!

For simplicity, start with this code to convince yourself:

import os
filename = raw_input("Plea se enter a filename: ")
os.startfile(fi lename)

Once you get that to work, replace raw_input with a function that gets
the filename from your GUI.

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context: http://www.nabble.com/problems-with-...p17787228.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #34
Alexnb wrote:
Haha, okay well sorry that I was being so stupid, but I get it now
and I apoligize for causing you all the frustration. But I did get it to
work finally.
Jun 27 '08 #35

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

Similar topics

19
2987
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and provide an open TD with a DIV in it for the content of this formlet. (The DIV is for DHTML to hide and show the content) I've created a web page showing step by step the two problems I'm encountering. This problem is much easier to see than it...
6
10217
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error message: "The process cannot access the file "whatever" because it is being used by another process." I've even tried opening another file using the same streamwriter object before deleting the original file, but it's no use. Something keeps...
5
3321
by: spike grobstein | last post by:
So, I've got this project I'm working on where the app defines various classes that are subclassed by module packages that act like plugins... I'd like the packages to define a file path for supporting files (graphics, etc) that are stored inside the package. The problem is that the superclass's definition (stored elsewhere) has all of the code for actually opening the files, so when I use the os.path.dirname(os.path.abspath(__file__))...
1
5396
by: electrixnow | last post by:
Help!, I need to compile this code with static libs so it run on another XP machine that does'nt have MS Studio installed. When I compile now I get an ERROR: 1>------ Rebuild All started: Project: drawing_control, Configuration: Release Win32 ------ 1>Deleting intermediate and output files for project 'drawing_control', configuration 'Release|Win32'
2
3275
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs thru. But once i add more, it dies. In this program i have 4 files setup to read. The
9
2199
by: Sheldon | last post by:
Good day Everyone, I am a still very new at learning C and I have thrown myself in the deep end. I started with a simple program and kept widening the scope. This has taught me many things about C and some, I must admit, have not really sunk in yet. Still, I push on. Now I am taken a library of C programs that were designed to read HDF files. I work on a Unix server and in Mandrake10. The program below is most likely broken but I cannot...
1
6332
by: sunil | last post by:
Hi all, I have a web application in which I have to open a "chm" file that exists on the local file system. I am able to open other files such as PDF, DOC files by writing the Response's output stream. But I do not exactly know the Response.ContentType for chm files. I have used the following code to handle the case for chm files System.IO.StreamReader sr = new System.IO.StreamReader(this.Path); FileInfo file = new FileInfo(this.Path);...
0
928
by: saif.shakeel | last post by:
HI, Thanks for the reply.that seems to work,but i was doing this so as to attach it to a bigger code where it will be utilised before a parsing. #Input file and Output file path from user file_input = raw_input("Enter The ODX File Path:")
0
1056
by: Alexnb | last post by:
Okay, so what I want my program to do it open a file, a music file in specific, and for this we will say it is an .mp3. Well, I am using the system() command from the os class. The problem I am running into is that when I send the path of the file to the system() command, which for those of you who don't know the system command is the equivalent of typing one command into command prompt or terminal depending on your system. But let's say...
0
9336
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
10111
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
9948
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...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6603
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
5215
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
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.