0

How to change the current working folder with python on my android Smartphone ?

Hi everyone , All is in the question, but if you have any doubt, I could try to reformulate. I know that I have to use a fonction in the module os which is named chdir. So to access and work on my directory "fichier.txt" I should code something like that ; >>> import os >>> os.chdir("Internal storage/Python_with_the_book/fichier.txt") But it doesn't work.. do you think that there is a mistake like, it's not "Internal storage" but "C" or maybe I should put ":" after "C" ? Thank you, Qwin

7th Nov 2020, 10:09 AM
Quorin Coln
Quorin Coln - avatar
7 Antworten
+ 12
You ca use something like this: import os os.chdir("/Internal storage/Python_with_the_book/") You should NOT: - use file name at the end of the path name You should: - use leading slash "/" in your path name
7th Nov 2020, 11:00 AM
Lothar
Lothar - avatar
+ 2
nah, print(os.getcwd()) and see where you are in your phone. for android (while using pydroid) the path looks like: /storage/emulated/0/Android/data/ru.iiec.pydroid3/files
7th Nov 2020, 10:15 AM
Slick
Slick - avatar
+ 2
Dear Lothar, Dear Slick, Youhouuuu ! It works !! 😄 I did what you have explained to me, the path was just a bit longer. >>> import os >>> os.chdir("/storage/emulated/0/Python_with_the_book/") Thanks a lot 🙂🤗
17th Nov 2020, 4:45 PM
Quorin Coln
Quorin Coln - avatar
+ 1
>>> import os >>> print(os.getcwd()) /storage/emulated/0 That is where I am 🤔
7th Nov 2020, 10:26 AM
Quorin Coln
Quorin Coln - avatar
0
Python 3.8.3 (default, May 27 2020, 02:08:17) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> os.chdir("Espace de stockage interne partagé:/Python_with_the_book/fichier.txt") Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'os' is not defined >>> That's what I have exactly. It's written "Python 3.8.3 --- on linux". The code should probably takes linux programmation rules into account . Right ?
7th Nov 2020, 10:23 AM
Quorin Coln
Quorin Coln - avatar
0
okay cool, first though, why running in interactive? you may as well cd into whatever directory you want, then start the interactive interpreter. But yeah, you can basically print out any folders or files and just follow it to your desired folder if you really want to do everything from within python.
7th Nov 2020, 10:30 AM
Slick
Slick - avatar
0
Does something like that would be better ? os.chdir("storage/Python_with_the_book/fichier.txt") No. Let's try: os.chdir("storage/emulated/Python_with_the_book/fichier.txt") I have to go to work. If some advise are given I'll read it after. Thank a lot 🙂
7th Nov 2020, 10:36 AM
Quorin Coln
Quorin Coln - avatar