-1
import os
impoer uuid
wallet_filepath = os.path.join( 'PWD', str(uuid.uuid4().hex) , '.bin')
print (wallet_filepath)
print (os.path.exists(wallet_filepath))
print (os.stat(wallet_filepath))

This is the OUTPUT that I am getting from this code.

/home/user/randomTests/b1c51a61c235479aa0964e14db7135d6/.bin

False

Traceback (most recent call last): File "testDir.py", line 9, in print (os.stat(wallet_filepath)) FileNotFoundError: [Errno 2] No such file or directory: '/home/user/randomTests/b1c51a61c235479aa0964e14db7135d6/.bin'

Ashish Ranjan
  • 5,523
  • 2
  • 18
  • 39

2 Answers2

2

You never created the directory! You're just creating a string path and storing it in wallet_filepath.

You can use os.makedirs to create the directory recursively (i.e, create all intermediate-level directories as well, needed to create the final dir):

wallet_filepath = os.path.join( 'PWD', str(uuid.uuid4().hex) , '.bin')
print (wallet_filepath)
if not os.path.exists(wallet_filepath) :
    os.makedirs(directory)
print (os.stat(wallet_filepath))
Ashish Ranjan
  • 5,523
  • 2
  • 18
  • 39
0

Additional to the answer given to use os.makedirs(), you may want to validate if your .join statement is actually what you want.

If you want "/home/user/randomTests/b1c51a61c235479aa0964e14db7135d6/.bin", keep using:

wallet_filepath = os.path.join( 'PWD', str(uuid.uuid4().hex) , '.bin')

If you want "/home/user/randomTests/b1c51a61c235479aa0964e14db7135d6.bin", use:

wallet_filepath = os.path.join( 'PWD', str(uuid.uuid4().hex) + '.bin')
Edwin van Mierlo
  • 2,398
  • 1
  • 10
  • 19