[android-developers] Re: How to execute "cd sdcard" command

2010-04-22 Thread karteek
Thanks Marks,Bob.
Your help is really appreciated,
I will follow java i/o.

On Apr 22, 9:39 pm, Bob Kerns  wrote:
> Mark points out all the reasons you shouldn't even be trying to do
> this.
>
> But there's more! I assume you're going to take Mark's advice anyway,
> but these are things that are likely to cause you trouble someday in
> the future, so I'll point them out anyway.
>
> First, you are trying to cd to some directory you have no reason to
> believe exists. You don't have any idea what your current directory is
> -- why should you expect it to have a 'sdcard' subdirectory? I expect
> you meant "/sdcard" -- and that might work on your device. It might
> not work on some other device, though. See this class for methods to
> handle this cleanly:
>
> http://developer.android.com/intl/de/reference/android/os/Environment...
> (You'll want to make use of this with Mark's advice, too).
>
> And even if you did manage to cd to a directory named 'sdcard' -- it
> would have NO EFFECT WHATSOEVER on the next command you execute!
>
> You ran a shell and told it to do 'cd sdcard'. When it's done with
> that, it exits. You no longer have a shell with that working
> directory. Now you try to run 'ls' in a new shell. This new shell
> doesn't care what you did in the old shell. It is NOT going to be
> executing in your sdcard directory.
>
> You could put these two commands into a .sh file, and execute that.
> But what's the point? You could supply the same path directly to 'ls'.
> Or even better, use the Java facilities for accessing the filesystem
> and avoid all kinds of bugs you'd probably introduce -- like, for
> example, handling spaces in filenames, etc.
>
> On Apr 22, 5:50 am, Karteek N  wrote:
>
>
>
>
>
> > Hi ,
> > I want to display what are the files and contents in sdcard through
> > application.
> > I am able to print the root folder.But when i execute cd sdcard
> > it throws me exception that permission is denied.
> > When i did the same thing using adb shell i am able to display the sdcard.
> > Is there any way to change permissions like sudo
>
> > I used the following code to display root folder
>
> >  Runtime rt = Runtime.getRuntime();
> >           try {
> >                    Process process;
> >                    process=rt.exec("ls");
> >                  try{
> >                           BufferedReader in =new BufferedReader(new
> > InputStreamReader(process.getInputStream()));
>
> >                          String line;
> >                          while ((line = in.readLine()) != null) {
> >                                Log.d("debug",line);
> >                                 }
> >                           in.close();
>
> >                       } catch (Exception e) {
> >                               e.printStackTrace();
> >                              System.out.println(e.getMessage());
> >                        }
>
> >                    } catch (IOException e) {
>
> >                           e.printStackTrace();
> >                   }
>
> > But when change the above code like
> >   process=rt.exec("cd sdcard");
> >   process=rt.exec("ls");
> > Its throws exception
>
> > Any help please
> > Regards,
> > Karteek
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group 
> > athttp://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: How to execute "cd sdcard" command

2010-04-22 Thread Bob Kerns
Mark points out all the reasons you shouldn't even be trying to do
this.

But there's more! I assume you're going to take Mark's advice anyway,
but these are things that are likely to cause you trouble someday in
the future, so I'll point them out anyway.

First, you are trying to cd to some directory you have no reason to
believe exists. You don't have any idea what your current directory is
-- why should you expect it to have a 'sdcard' subdirectory? I expect
you meant "/sdcard" -- and that might work on your device. It might
not work on some other device, though. See this class for methods to
handle this cleanly:

http://developer.android.com/intl/de/reference/android/os/Environment.html
(You'll want to make use of this with Mark's advice, too).

And even if you did manage to cd to a directory named 'sdcard' -- it
would have NO EFFECT WHATSOEVER on the next command you execute!

You ran a shell and told it to do 'cd sdcard'. When it's done with
that, it exits. You no longer have a shell with that working
directory. Now you try to run 'ls' in a new shell. This new shell
doesn't care what you did in the old shell. It is NOT going to be
executing in your sdcard directory.

You could put these two commands into a .sh file, and execute that.
But what's the point? You could supply the same path directly to 'ls'.
Or even better, use the Java facilities for accessing the filesystem
and avoid all kinds of bugs you'd probably introduce -- like, for
example, handling spaces in filenames, etc.

On Apr 22, 5:50 am, Karteek N  wrote:
> Hi ,
> I want to display what are the files and contents in sdcard through
> application.
> I am able to print the root folder.But when i execute cd sdcard
> it throws me exception that permission is denied.
> When i did the same thing using adb shell i am able to display the sdcard.
> Is there any way to change permissions like sudo
>
> I used the following code to display root folder
>
>  Runtime rt = Runtime.getRuntime();
>           try {
>                    Process process;
>                    process=rt.exec("ls");
>                  try{
>                           BufferedReader in =new BufferedReader(new
> InputStreamReader(process.getInputStream()));
>
>                          String line;
>                          while ((line = in.readLine()) != null) {
>                                Log.d("debug",line);
>                                 }
>                           in.close();
>
>                       } catch (Exception e) {
>                               e.printStackTrace();
>                              System.out.println(e.getMessage());
>                        }
>
>                    } catch (IOException e) {
>
>                           e.printStackTrace();
>                   }
>
> But when change the above code like
>   process=rt.exec("cd sdcard");
>   process=rt.exec("ls");
> Its throws exception
>
> Any help please
> Regards,
> Karteek
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en