I would like to present a problem that came up with the outputs of a list in python, the fact is that I am doing a program that runs through the directories of a PC, by getting the first list of directories (The one that is available from the first working directory) has to access the lists found in that directory, and that's where it fails:
import os
import ftplib
carpetas = []
actuals = os.getcwd()
print actuals
def paso1 ():
lista = os.listdir(".")
for x in lista:
if os.path.isdir(x) == True:
num = lista.index(x)
carpetas.append(lista[num])
paso1()
def paso2():
for i in carpetas:
os.chdir(i)
direct = str(os.getcwd())
directorios = {direct : ""}
lista = os.listdir(".")
for x in lista:
if os.path.isdir(x) == True:
num = lista.index(x)
directorios[direct].append(lista[num])
os.chdir("..")
step2 ()
When I try to access the following directory in "os.chdir (i)" it gives an error, since "i" is presented with quotation marks, like the outputs of a list.
Can you think of any way for the output to be without quotes?
The error:
/home/angrymasther/Escritorio
Traceback (most recent call last):
File "Servidor2.py", line 28, in <module>
paso2()
File "Servidor2.py", line 17, in paso2
os.chdir(i)
OSError: [Errno 2] No such file or directory: 'Web'
Thanks in advance.