Maybe not a Ruby question but I still need to know

K

Kaye Ng

I'm using windows XP. I save my practice files in my thumb drive -
H:\Ruby\Practice , this directory is added to the path variables (in
Environment Variables), so that when I open command prompt and the
default directory is C:\Documents and Settings\user> , I can run my
problem example1.rb (which is in H:\Ruby\Practice) by typing "example1"
like so:

C:\Documents and Settings\user>example1

and it would run just fine, even if example1.rb is not in the default or
current directory (C:\Documents and Settings\user>).

However, I have another file saved in the same folder as example1.rb (in
the thumb drive), and the code opens a text file (about 18 paragraphs
worth of text). Why is it that I cannot run it directly from
C:\Documents and Settings\user like I did with example1.rb? I have to
go to H:\Ruby\Practice and type in the text file's filename.

Thanks guys!
 
R

Rajinder Yadav

I'm using windows XP. I save my practice files in my thumb drive -
H:\Ruby\Practice , this directory is added to the path variables (in
Environment Variables), so that when I open command prompt and the
default directory is C:\Documents and Settings\user> , I can run my
problem example1.rb (which is in H:\Ruby\Practice) by typing "example1"
like so:

C:\Documents and Settings\user>example1

and it would run just fine, even if example1.rb is not in the default or
current directory (C:\Documents and Settings\user>).

However, I have another file saved in the same folder as example1.rb (in
the thumb drive), and the code opens a text file (about 18 paragraphs
worth of text). Why is it that I cannot run it directly from
C:\Documents and Settings\user like I did with example1.rb? I have to
go to H:\Ruby\Practice and type in the text file's filename.

Thanks guys!

what are you saying? that you want"H:\Ruby\Practice\example1.rb" to run
when you are in "C:\Documents and Settings\user" ?? if that's what
you're asking it can't be done just using the filname! Either you CD
into the folder, or provide the full pathname + filename,
"H:\Ruby\Practice\example1.rb"

--
Kind Regards,
Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

GNU/Linux: 2.6.35-22-generic
Kubuntu x86_64 10.10 | KDE 4.5.1
Ruby 1.9.2p0 | Rails 3.0.1
 
K

Kaye Ng

what are you saying? that you want"H:\Ruby\Practice\example1.rb" to run
when you are in "C:\Documents and Settings\user" ?? if that's what
you're asking it can't be done just using the filname! Either you CD
into the folder, or provide the full pathname + filename,
"H:\Ruby\Practice\example1.rb"
Yes I can and I have been doing that for several months now. That's
because I've added "H:\Ruby\Practice" in my PATH VARIABLES
 
K

Kendall Gifford

Yes I can and I have been doing that for several months now. =A0That's
because I've added "H:\Ruby\Practice" in my PATH VARIABLES

Does this other file in "H:\Ruby\Practice\" refuse to run at all:

C:>Documents and Settings\me> my-script.rb
'my-script.rb' is not recognized as an internal or external command,
operable program or batch file

Or does it run but raise an exception when it tries to run the code that
opens the text file you mentioned? I ask because I suspect this is an
issue of your "current working directory" being different and the fact that
you are opening this text file using a relative path name.

--=20
Kendall Gifford
(e-mail address removed)
 
K

Kaye Ng

To Kendall Gifford,

someone answered me in another forum:
The PATH environment variable gives you access to executable files only.
Other file types, such as text files are not treated that way.
To do that you would use the APPEND command which sadly is obsolete now.
You may work around it by creating a CMD file such as a textfile.cmd
containing the commands:

@echo off
notepad H:\Ruby\Practice\textfile.txt

The bad news is you would have to create a CMD file for each text file
you want to open this way.

Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top