$: = '/users/joecool/rubylib'
$: << '/users/joecool/rubylib'
$:.unshift('/users/joecool/rubylib')
ruby -c somescript.rb
ruby -e "puts 'Hello, world!'
Run Code Online (Sandbox Code Playgroud)
有人可以指导我阅读,以便我可以弄清楚这段代码的作用吗?
我有一个perl脚本:run.pl,每分钟都被cron调用.
run.pl唯一要做的就是调用另外两个脚本:download.pl和parse.pl:
#!/usr/bin/perl
use warnings;
use strict;
do 'download.pl';
do 'parse.pl';
print "done!\n";
Run Code Online (Sandbox Code Playgroud)
在download.pl和parse.pl两种打印与"下载完成"和"做了分析:"现在我把脚本输出到/var/log/script.log并检查脚本运行.
run.pl脚本运行正常,它输出"done!" 到日志文件.但是没有调用其他两个脚本.我认为这是一个相对路径问题,它在我使用绝对路径时起作用.
但这就是问题,脚本在测试阶段并且每次都改变路径,总是改变绝对路径会很麻烦.
有没有办法让脚本从相对路径运行?
编辑:当我自己从命令行运行"perl run.pl"时,它运行脚本没有问题.
我需要../something/从网址中删除
例如.剥离../first/从../first/bit/of/the/url.html哪里first可以是任何东西.
实现这一目标的最佳方法是什么?
谢谢 :)
什么相当于System.IO.Path?
我有这个网址:http://www.website.com/category1/category2/file.aspx? data = 123
我怎么能打破这个,比如
var url = ASPNETPATH("http://www.website.com/category1/category2/file.aspx?data=123");
url.domain <-- this would then return http://www.website.com
url.folder <-- would return category1/category2
url.file <-- would return file.aspx
url.queryString <-- would return the querystring in some format
Run Code Online (Sandbox Code Playgroud) 我有大量的文件路径和文件扩展名来处理:
我的目标是轻松检索与给定文件扩展名关联的所有文件路径.
例如,如果我问"mp3",我想知道具有该扩展名的文件的所有路径.
现在,我的问题是:我应该使用哪个C#集合来最佳地执行此操作以及如何使用该集合?
我编写了一个c ++程序并将其部署在c:\ my_app中,我的可执行文件的路径是c:\ my_app\my_app.exe.比方说,my_app需要许多文件,例如the_file.txt,它位于c:\ my_app\the_file.txt中.
在我的可执行文件中,我将txt文件打开为xx.open("the_file.txt");
此外,我已经将我的程序与.myp扩展相关联.
当我在桌面上,并且想要打开一个名为example.myp的文件时,我的程序看不到the_file.txt.因为,它(以某种方式)假设它当前正在桌面上工作.
有没有简单的方法来通过更改HKEY_CLASSES_ROOT中打开的shell命令来处理此问题?天真的解决方案是使用类似"%my_app_location/the_file.txt"的内容来更改所有文件打开操作.我不想那样做.
感谢你的帮助.
我曾经知道它,但我知道在java中有一种方法可以确保路径在所有操作系统中都有效(Windows使用与基于Unix的系统不同的"/"系统).如何创建适用于所有系统的文件路径名,我该怎么做?
编辑:我不确定这是否是我的意思,但我认为文件路径最终将是相对的.
另外,File.separator和File.pathSeparator之间有什么区别?
我有一个非常基本的问题要问,为什么我们需要在PATH变量的末尾添加分号,为什么不在JAVA_HOME变量中添加分号?
我读了很多书和论坛:
要在PATH变量中分隔不同的路径?或告诉系统或JRE之后不要再看了。
JAVA_HOME变量用于帮助JRE在将来的开发中查找更多文件和扩展名,例如JDBC驱动程序等。
在我的Java应用程序中,我需要使用JFileChooser选择路径.我写的代码如下:
jfChooser = new JFileChooser();
jfChooser.setCurrentDirectory(new java.io.File("."));
jfChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (jfChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): "+ jfChooser.getCurrentDirectory());
System.out.println("getSelectedFile() : "+ jfChooser.getSelectedFile());
tfPath.setText(jfChooser.getSelectedFile().getAbsolutePath()); // the selected path set to textfield which is lated get by the program
}
else {
System.out.println("No Selection ");
}
Run Code Online (Sandbox Code Playgroud)
我正在获得正确的路径.例如,这里我得到的路径(在Windows操作系统中)
String choosedPath=tfPath.getText().trimm();
Run Code Online (Sandbox Code Playgroud)
现在实际上我想以编程方式在给定路径(即newfolder目录中)上创建另一个目录.
为此,我有新的目录名称"newdir",因此传递给File构造函数以创建此目录的字符串如下所示:
File createFolder = new File("choosedPath"+"\\"+"newdir");
Run Code Online (Sandbox Code Playgroud)
现在问题是我的应用程序可能在Windows上运行或者可能在Linux上运行,因此文件路径分隔符会有所不同(例如,对于Windows为'/',对于linux为'\')
我如何克服这个问题,以便根据操作系统获得路径中的propper斜杠?
有人可以告诉我为什么下面的代码正在搜索指定路径中的子文件夹.我只想要搜索c:\ Python27中的所有.txt和.log文件.但搜索显示c:\ Python27\Doc中的.txt和.log文件的结果......依此类推.谢谢.
elif searchType =='3':
print "Directory to be searched: c:\Python27 "
print " "
directory = os.path.join("c:\\","Python27")
regex = re.compile(r'3[0-9]\d{10}')
for root,dirname, files in os.walk(directory):
for file in files:
if file.endswith(".log") or file.endswith(".txt"):
f=open(os.path.join(root,file))
for line in f.readlines():
searchedstr = regex.findall(line)
for word in searchedstr:
print "String found: " + word
print "File: " + os.path.join(root,file)
break
f.close()
Run Code Online (Sandbox Code Playgroud)