0
$\begingroup$
FileBaseName["F:\\2016-02-23\\11.5_mm_fan_off_pumps_off_1500_hz_3793_\
images_2048_1472_pixels_20160223_1649_time_part"]

should give the base folder name:

"11.5_mm_fan_off_pumps_off_1500_hz_3793_images_2048_1472_pixels_20160223_1649_time_part"

but due to the dot after 11 the result is:

"11"

How can I solve that?

$\endgroup$
4
  • 2
    $\begingroup$ if that's a directory: FileNameTake[path, -1] $\endgroup$
    – Kuba
    Commented Mar 1, 2016 at 15:01
  • $\begingroup$ It looks like you are looking for FileNameTake, not FileBaseName. FileBaseName does what it's supposed to here: it removes the extension, i.e. everything after the last dot. Note that directories can have extensions too, see e.g. .app on OS X. $\endgroup$
    – Szabolcs
    Commented Mar 1, 2016 at 15:01
  • 2
    $\begingroup$ @Kuba Actually the -1 is not needed. It always takes the last element of the path, whether that is a directory or not. $\endgroup$
    – Szabolcs
    Commented Mar 1, 2016 at 15:02
  • $\begingroup$ @Szabolcs I don't know why I wasn't aware of that, thanks ;) $\endgroup$
    – Kuba
    Commented Mar 1, 2016 at 15:04

1 Answer 1

5
$\begingroup$

The purpose of FileBaseName is not to take the last element of the path. It's purpose is to remove the file extension, i.e. everything after the last dot in the name. Directories can have extensions too, see e.g. .app on OS X. In your example FileBaseName is working correctly and doing what it should.

If you want to take the last element of the path, use FileNameTake.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.