Ask coding questions

← Back to all posts
how to get directory path
TheBlockkingBlo (0)

i am asking how to get the directory path because when i have this in my code 'os.chdir('mainprofile.json')' i get this error
'NotADirectoryError: [Errno 20] Not a directory: 'mainprofile.json''

Answered by GatewayDuckYT (60) [earned 5 cycles]
View Answer
GatewayDuckYT (60)

The directory path would be
/home/runner/<project name>/<file path>
Click the check if this helped
Need more help? just reply to this

GatewayDuckYT (60)

@GatewayDuckYT in js i would do

function getPath(path) {
var path = '/home/runner/<project name/' + path
return path;
var path = getPath('bob.png')
TheBlockkingBlo (0)

@GatewayDuckYT I'm using python ( should have said that sorry

GatewayDuckYT (60)

@TheBlockkingBlo the paths would still be the same

def getPath(path):
   '/home/runner/<project name/' + path
    return path
path = getPath('bob.png')
TheBlockkingBlo (0)

@GatewayDuckYT how would i add os.chdir() into this? (im kinda new with replit sorry)

TheBlockkingBlo (0)

@GatewayDuckYT i still get the same error when i try this