LoginSignup
4
3

More than 5 years have passed since last update.

スクリプトの存在するディレクトリーの絶対パスを取得する

Last updated at Posted at 2018-05-06

Python2〜3.3

import os

print os.path.dirname(os.path.abspath(__file__))

元ネタ

Python 3.4 以降

from pathlib import Path
print(Path(__file__).resolve().parent)

Ruby

p __dir__

元ネタ

shell

#!/bin/sh

(cd `dirname $0`; pwd)

Perl

#!/usr/bin/env perl

use strict;
use warnings;

use FindBin;
print "$FindBin::Bin\n"

元ネタ

4
3
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3