当前脚本文件名可以通过以下方法获取:
__file__
变量获取当前脚本文件名。例如:import os
script_filename = os.path.basename(__file__)
print(script_filename)
__filename
变量获取当前脚本文件名。例如:const path = require('path');
const script_filename = path.basename(__filename);
console.log(script_filename);
Thread.currentThread().getStackTrace()
方法获取当前脚本文件名。例如:import java.lang.Thread.StackTraceElement;
public class Main {
public static void main(String[] args) {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
String script_filename = stackTraceElements[1].getFileName();
System.out.println(script_filename);
}
}
__FILE__
常量获取当前脚本文件名。例如:$script_filename = basename(__FILE__);
echo $script_filename;
__FILE__
常量获取当前脚本文件名。例如:script_filename = File.basename(__FILE__)
puts script_filename
System.IO.Path.GetFileName()
方法获取当前脚本文件名。例如:using System;
class Program {
static void Main() {
string script_filename = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Console.WriteLine(script_filename);
}
}
os.Args[0]
获取当前脚本文件名。例如:package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
script_filename := filepath.Base(os.Args[0])
fmt.Println(script_filename)
}
__filename
变量获取当前脚本文件名。例如:const path = require('path');
const script_filename = path.basename(__filename);
console.log(script_filename);
CommandLine.arguments[0]
获取当前脚本文件名。例如:import Foundation
let script_filename = URL(fileURLWithPath: CommandLine.arguments[0]).lastPathComponent
print(script_filename)
args[0]
获取当前脚本文件名。例如:import java.io.File
fun main(args: Array<String>) {
val script_filename = File(args[0]).name
println(script_filename)
}
std::env::args()
获取当前脚本文件名。例如:use std::env;
use std::path::Path;
fn main() {
let args: Vec<String> = env::args().collect();
let script_filename = Path::new(&args[0]).file_name().unwrap().to_str().unwrap();
println!("{}", script_filename);
}
$0
变量获取当前脚本文件名。例如:use File::Basename;
my $script_filename = basename($0);
print "$script_filename\n";
arg[0]
获取当前脚本文件名。例如:local script_filename = arg[0]
print(script_filename)
args(0)
获取当前脚本文件名。例如:import java.io.File
object Main {
def main(args: Array[String]): Unit = {
val script_filename = new File(args(0)).getName
println(script_filename)
}
}
(car (command-line))
获取当前脚本文件名。例如:(display (car (command-line)))
CommandLine commandLine
获取当前脚本文件名。例如:Transcript show: CommandLine commandLine first
init:get_plain_arguments()
获取当前脚本文件名。例如:main(_Args) ->
[ScriptFilename|_] = init:get_plain_arguments(),
io:format("~s~n", [ScriptFilename]).
current_prolog_flag(argv, Args)
获取当前脚本文件名。例如:main :-
current_prolog_flag(argv, Args),
atom_string(Args, ScriptFilename),
write(ScriptFilename).
System.Environment.getArgs
获取当前脚本文件名。例如:import System.Environment (getArgs)
main :: IO ()
main = do
args <- getArgs
putStrLn (head args)
System.Environment.GetCommandLineArgs()
获取当前脚本文件名。例如:open System
[<EntryPoint>]
let main argv =
let script_filename = Environment.GetCommandLineArgs().[0]
printfn "%s" script_filename
0
My.Application.CommandLineArgs(0)
获取当前脚本文件名。例如:Module Module1
Sub Main()
Dim script_filename As String = My.Application.CommandLineArgs(0)
Console.WriteLine(script_filename)
Console.ReadLine()
End Sub
End Module
[[NSProcessInfo processInfo] arguments]
获取当前脚本文件名。例如:#import<Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSArray *args = [[NSProcessInfo processInfo] arguments];
NSString *script_filename = [args firstObject];
NSLog(@"%@", script_filename);
}
return 0;
}
*command-line-args*
获取当前脚本文件名。例如:(println (first *command-line-args*))
commandArgs()
获取当前脚本文件名。例如:args <- commandArgs()
script_filename <- args[1]
cat(script_filename)
argv
获取当前脚本文件名。例如:puts [lindex $argv 0]
ParamStr(0)
获取当前脚本文件名。例如:begin
WriteLn(ParamStr(0));
end.
command_argument_count()
和get_command_argument()
获取当前脚本文件名。例如:program main
integer :: argc
character(len=1024) :: script_filename
call get_command_argument(0, script_filename)
print *, trim(script_filename)
end program main
args[0]
获取当前脚本文件名。例如:import std.stdio;
void main(string[] args) {
string script_filename = args[0];
writeln(script_filename);
}
std::env::args()
获取当前脚本文件名。例如:use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
let script_filename = &args[0];
println!("{}", script_filename);
}
ARGS
获取当前脚本文件名。例如:script_filename = ARGS[1]
println(script_filename)
System.argv()
获取当前脚本文件名。例如:script_filename = List.first(System.argv())
IO.puts(script_filename)
init:get_plain_arguments()
获取当前脚本文件名。例如:main(_Args) ->
[ScriptFilename|_] = init:get_plain_arguments(),
io:format("~s~n", [ScriptFilename]).
current_prolog_flag(argv, Args)
获取当前脚本文件名。例如:main :-
current_prolog_flag(argv, Args),
atom_string(Args, ScriptFilename),
write(ScriptFilename).
System.Environment.getArgs
获取当前脚本文件名。例如:import System.Environment (getArgs)
main :: IO ()
main = do
args <- getArgs
putStrLn (head args)
System.Environment.GetCommandLineArgs()
获取当前脚本文件名。例如:open System
[<EntryPoint>]
let main argv =
let script_filename = Environment.GetCommandLineArgs().[0]
printfn "%s" script_filename
0
My.Application.CommandLineArgs(0)
获取当前脚本文件名。例如:Module Module1
Sub Main()
Dim script_filename As String = My.Application.CommandLineArgs(0)
Console.WriteLine(script_filename)
Console.ReadLine()
End Sub
End Module
[[NSProcessInfo processInfo] arguments]
获取当前脚本文件名。例如:#import<Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSArray *args = [[NSProcessInfo processInfo] arguments];
NSString *script_filename = [args firstObject];
NSLog(@"%@", script_filename);
}
return 0;
}
*command-line-args*
获取当前脚本文件名。例如:(println (first *command-line-args*))
commandArgs()
获取当前脚本文件名。例如:args <- commandArgs()
script_filename <- args[1]
cat(script_filename)
argv
获取当前脚本文件名。例如:puts [lindex $argv 0]
ParamStr(0)
获取当前脚本文件名。例如:begin
WriteLn(ParamStr(0));
end.
command_argument_count()
和get_command_argument()
获取当前脚本文件名。例如:program main
integer :: argc
character(len=1024) :: script_filename
call get_command_argument(0, script_filename)
print *, trim(script_filename)
end program main
args[0]
获取当前脚本文件名。例如:import std.stdio;
void main(string[] args) {
string script_filename = args[0];
writeln(script_filename);
}
std::env::args()
获取当前脚本文件名。例如:use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
let script_filename = &args[0];
println!("{}", script_filename);
}
ARGS
获取当前脚本文件名。例如:script_filename = ARGS[1]
println(script_filename)
System.argv()
获取当前脚本文领取专属 10元无门槛券
手把手带您无忧上云