Viewed   89 times

For example, how do I get Output.map

from

F:Program FilesSSH Communications SecuritySSH Secure ShellOutput.map

with PHP?

 Answers

4

You're looking for basename.

The example from the PHP manual:

<?php
$path = "/home/httpd/html/index.php";
$file = basename($path);         // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
?>
Monday, September 26, 2022
3

Windows in particular has a very short file name limit in its original Win32 API. This general problem is discussed here at SO.

At most about 260 characters can be used in an absolute path on Win32. On other platforms there are other limits, but at least 512 characters is to be expected and more is not unheard of.

(For instance, in GNU HURD, there effectively is no limit to file lengths, even though the underlying file system may impose a limit.)

However, Windows actually can have longer filenames (obviously, as you have them on your computer). This works by using a newer Windows API. Unfortunately, standard PHP does not use this API, as far as I know.

There is a modified version of PHP which makes use of this newer Windows API over at Github.

Another benefit from using that newer API is that it also supports Unicode characters in the file names.

Saturday, August 27, 2022
 
simplej
 
5

just use File.getName()

File f = new File("C:\Hello\AnotherFolder\The File Name.PDF");
System.out.println(f.getName());

using String methods:

  File f = new File("C:\Hello\AnotherFolder\The File Name.PDF");  
System.out.println(f.getAbsolutePath().substring(f.getAbsolutePath().lastIndexOf("\")+1));
Thursday, November 10, 2022
 
2

$_SERVER["PHP_SELF"]; returns what you want

Monday, October 24, 2022
1
@echo off
set FILEPATH=\srv-01My DocsTemplatesMy SpreadSheet.xls
for /F "delims=" %%A in ("%FILEPATH%") do set "FILEPATH=%%~nxA"
echo.%FILEPATH%
Friday, November 25, 2022
 
giogadi
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :