OsError Python on Ubuntu

0

I have created a script with Python and when executing it, it responds with this message:

Traceback (most recent call last):
  File "./pruebaHIDS.py", line 6, in <module>
    for filename in listdir("/Escritorio/Scripts"):
OSError: [Errno 2] No such file or directory: '/Escritorio/Scripts'

The problem comes because the directory in particular Desktop / Scripts is not empty.

Does anyone think of a solution or has it happened before?

Edit:

Changing the path to "/ home / ldh / Desktop / Scripts /" as advised in the comments I get a new error:

Traceback (most recent call last): 
  File "pruebaHIDS.py", line 11, in <module>
    print "excepción: " % e
TypeError: not all arguments converted during string formatting

I enclose the code that I am running:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import hashlib
from os import listdir
from os.path import isdir, islink
for filename in listdir("/home/ldh/Escritorio/Scripts/"):
 if not isdir(filename) and not islink(filename):
  try:
   f = open(filename)
  except IOError, e:
   print "excepción: " % e
 else:
  data = f.read()
  f.close()
  print "** %s **" % filename
  for algorithm in hashlib.algorithms:
   h = getattr(hashlib, algorithm)(data)
   print "%s: %s" % (algorithm, h.hexdigest())
   print ""
    
asked by Yo Yo 09.10.2017 в 23:23
source

1 answer

0

As the routes in Linux are resolved the route:

"home/ldh/Escritorio/Scripts/"

is a relative route and is treated as such. This causes you to look for the home directory within the current working directory, or the default script.

A slash must be added to the left so that the route is treated as absolute:

"/home/ldh/Escritorio/Scripts/"

Edit:

Your second error is because on the line:

print "excepción: " % e

You pass the argument e to be formatted but you do not include the appropriate indicator in the string itself. It should be:

print "excepción: %s" % e
    
answered by 10.10.2017 в 19:00