Very good afternoon with all…
I’m learning PYTHON and I’m learning how to import external libraries.
I would like to know what command I should type in order to see ALL THE CONTENT OF THE FOLDER I am addressing… thanks…
@Draxl_Andreas
he content that a DIR gives me is not the content that is in the directory path…
I want to see the contents of the folder.
Hello,
an example, to see all modules/packages loaded (.Net and Python)
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
import os
import System
assemblies = System.AppDomain.CurrentDomain.GetAssemblies()
for a in System.AppDomain.CurrentDomain.GetAssemblies():
if a.GetName().Name == 'IronPython.Modules':
mods = a
break
nativeIronpythonModule = [m.Key for m in mods.IronPython.Modules]
pythonimportModules = sys.modules.keys()
OUT = assemblies, nativeIronpythonModule, pythonimportModules
I was only looking to know the name of the files and their extension… because they are difficult…
I don’t understand anything… instead of being motivated to learn… now I want to learn it less…
…
Why is it so difficult to get just what I’m looking for… I just want to know the names and their extension of everything that is inside the folder… NOTHING ELSE… I’m not interested in knowing other things… I get confused more
“Be water my friend…” Bruce Lee
Is this more of what you were looking for @ammed.riveros
import sys
# Use a variable for the path to be able to call it other functions
iPath = 'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(iPath)
# To check contents of operating system
import os
files = []
folders = []
# Get the contents of the directory
directory_contents = os.listdir(iPath)
# Check contents for type sorting
for path in directory_contents:
# check if current path is a file by combining the directory and the path item
if os.path.isfile(os.path.join(iPath, path)):
# Its a file
files.append(path)
else:
# Its a folder
folders.append(path)
OUT = files,folders
here an example, but what is the end goal?, you search a library before import ?
import sys
import clr
import System
from System.IO import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
my_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)
pf_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86)
ironpath = pf_path + '\\IronPython 2.7\\Lib'
sys.path.append(ironpath)
lstFiles = Directory.GetFiles(ironpath, "*", SearchOption.TopDirectoryOnly)
lstDir = Directory.GetDirectories(ironpath, "*", SearchOption.TopDirectoryOnly)
OUT = list(lstDir) + list(lstFiles)
See if this page helps: Python - List Files in a Directory - GeeksforGeeks
Gracias…