Tag: 目录文件

如何在PHP中获得平台无关的目录分隔符?

我正在PHP中build立一个pathstring。 我需要它跨平台(即Linux,Windows,OS X)工作。 我正在这样做: $path = $someDirectory.'/'.$someFile; 假设$someDirectory和$someFile在运行时在各种平台上正确格式化。 这在Linux和OS X上运行良好,但在Windows上不能运行。 问题是我认为可以在Windows上使用的/字符。 有没有一个PHP函数或一些其他技巧,在Windows上运行时切换到\ ? 编辑:只是要清楚,结果string是 c:\Program Files (x86)\Sitefusion\Sitefusion.org\Defaults\pref/user.preferences 在Windows上。 显然,斜线混淆了Windows。

在Python中提取一部分文件path(一个目录)

我需要提取某个path的父目录的名称。 这就是它的样子: c:\ stuff \ directory_i_need \ subdir \ file 。 我正在修改“文件”的内容,使用其中的directory_i_need名称(而不是path)。 我创build了一个函数,它会给我一个所有文件的列表,然后… for path in file_list: #directory_name = os.path.dirname(path) # this is not what I need, that's why it is commented directories, files = path.split('\\') line_replace_add_directory = line_replace + directories # this is what I want to add in the text, with the directory […]