EigenFunctions has asked for the wisdom of the Perl Monks concerning the following question:
I write scripts in tcsh (sorry, not bash) and programs in Perl (in the past, I've written a lot in "C"). In both cases (tcsh and Perl), I have problems with filenames that contain special characters. I use (){}[]!# in most of my filenames and folder names, some of which came from the old days of windoz. My laptops run either Ubuntu or Debian and I use nautilus to access files and it understands these files and folder.
A Perl snippet as an example of the problem:
use String::ShellQuote; # this package almost n +ever works my $Temp = shell_quote_best_effort('BulletinV3, 1 Montana 20xx-xx-xx ( +print).pdf_FN_TEMPLATE'); if (-e $Temp) { `zenity --width 300 --info --text 'DBG> Got it!'`; } else { `zenity --width 300 --error --text 'DBG> Nope, not found!'`; # thi +s is what I get all the time } $rc = rename("BulletinV3, 1 Montana 20xx-xx-xx (print).pdf_FN_TEMPLATE +", "BulletinV3, 1 Montana $SundayDate (print).pdf_FN_TEMPLAT +E"); if($rc == 1) { $ExtTypes{'pdf_FN_TEMPLATE'}++; } else { `zenity --title \"Rename problem\" --width 400 --error --text \"Fi +le rename error (\\\"$!\\\"; \\\"BulletinV3, 1 Montana 20xx-xx-xx (pr +int).pdf_FN_TEMPLATE\\\")\"`; }
I know the file is there, I can see it, I can show it with ls (on the command-line), but the Perl program does not. I've tried all manner of quoting with backslashes, single and double quotes etc. I've tried using back-ticks with Linux 'mv' commands instead of rename() but in all the cases, nothing works. I've been plagued with this problem for years and, sometimes, I can find unique ways to deal with it. I'd like a way that I can use for all situations (it seems, nautilus has a solution that works).
Any help would be greatly appreciated.
Thanks,
EigenFunctions
OpSys: Ubuntu 18.04;
Perl: Perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux-gnu-thread-multi (with 71 registered patches)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems with special characters in Linux file names
by ikegami (Patriarch) on Sep 13, 2022 at 15:13 UTC | |
by EigenFunctions (Beadle) on Sep 13, 2022 at 15:32 UTC | |
by EigenFunctions (Beadle) on Sep 13, 2022 at 15:47 UTC | |
by Your Mother (Archbishop) on Sep 14, 2022 at 10:45 UTC | |
|
Re: Problems with special characters in Linux file names
by afoken (Chancellor) on Sep 13, 2022 at 18:30 UTC | |
by ikegami (Patriarch) on Sep 18, 2022 at 21:01 UTC | |
|
Re: Problems with special characters in Linux file names
by Anonymous Monk on Sep 16, 2022 at 06:17 UTC |