Re: File name is long to copy
by syphilis (Archbishop) on Apr 27, 2020 at 08:56 UTC
|
I copied your directory set up, along with the filename, and ran your script on perl-5.12.0 on Windows 7 and it worked fine for me.
I did add a couple of lines to check that both the file ($source) and the destination directory ($target) existed:
use strict;
use warnings;
use File::Copy;
my $source="C:\\sandboxes\\source_backup\\source_backup\\source_develo
+p\\source_folder\\source_part\\source_specific\\source_common\\rb_src
+c_sourcedevelopfolderpartspe_Interfacessourcecommonspecific.h";
my $target="C:\\sandboxes\\target_backup\\target_backup\\target_develo
+p\\generated\\_hnv_scan\\_source_develop\\source_folder\\source_part\
+\source_specific\\source_common";
print "OK 1\n" if -e $source;
print "OK 2\n" if -d $target;
copy($source,$target) or die "could not do: $!";
print ("done");
I got:
C:\_32\pscrpt>perl try.pl
OK 1
OK 2
done
C:\_32\pscrpt>
However, the first time I ran it, it failed because I had not named the $target directories correctly.
I had missed the underscores at the beginning of "_hnv_scan" and "_source_develop", and the script therefore produced:
C:\_32\pscrpt>perl try.pl
OK 1
could not do: at try.pl line 10.
Please do check that both the $target directory and $source file do actually exist, as it seems to me that the most likely explanation of your issue is a typographical error.
Cheers, Rob | [reply] [d/l] [select] |
Re: File name is long to copy
by marto (Cardinal) on Apr 26, 2020 at 13:18 UTC
|
What error are you getting? You could be hitting some OS (which?) based path depth limit. Let perl tell you what happened:
copy( $source, $target ) or die "couldn't copy file $!";
| [reply] [d/l] |
|
copy( $source, $target ) or die "couldn't copy file '$source' to '$tar
+get': $!";
| [reply] [d/l] |
|
| [reply] |
|
|
|
|
| [reply] |
|
copy( $source, $target ) or die "couldn't copy file $!";
#---------------------------------------------------^
| [reply] [d/l] [select] |
|
|
|
|
|
Re: File name is long to copy
by 1nickt (Canon) on Apr 26, 2020 at 14:32 UTC
|
Hi,
Did you try the copy outside your Perl program on the command line, cutting and pasting the pathnames from your code?
I see that when you printed the error it stated that the file or path does not exist.
Hope this helps!
The way forward always starts with a minimal test.
| [reply] |
|
| [reply] |
Re: File name is long to copy
by NetWallah (Canon) on Apr 27, 2020 at 00:36 UTC
|
source_specific
-><---
has HTML between the "o" and the "u".
The HTML says:
<font color="red"><b><u><wbr></u></b></font>
THis is also true of $target.
I'm not sure if that is an artifact of the way this site renders the code .. but there appears to be a problem with what it contains.
"Imaginary friends are a sign of a mental disorder if they cause distress, including antisocial behavior. Religion frequently meets that description"
| [reply] [d/l] [select] |
|
I don't see anything like that in the post, so it must be how this site renders the code for you. Check Code Wrapping in your Display Settings.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [d/l] |
|
Thank you for pointing that out -- Yes - it does appear to have something to do with local rendering.
My setting has "Code Wrap Length" set to 100 , and "Auto Code Wrapping" enabled.
The inserted HTML starts at the 104'th character, so it is likely that some characters (probably backslashes \\) do not count.
The inserted HTML does have a clue that it has to do with wrapping:
<font color="red"><b><u><wbr></u></b></font>
I learned that:
The <wbr> (Word Break Opportunity) tag specifies where in a text it would be ok to add a line-break.
"Imaginary friends are a sign of a mental disorder if they cause distress, including antisocial behavior. Religion frequently meets that description"
| [reply] [d/l] |
Re: File name is long to copy
by jcb (Parson) on Apr 28, 2020 at 01:42 UTC
|
Your problem is almost certainly Windows. You will need to work around some Microsoft dain bramage by changing to the source directory, opening the source file using a relative filename, changing to the target directory, opening the target file using a relative filename, and then copying the file contents. Note that you may have to change directories in steps (chdir('C:\sandboxes\source_backup\source_backup\source_develop') && chdir('.\source_folder\source_part\source_specific') && chdir('.\source_common') or die "chdir: $!"; is one possibility) if the directories are themselves deeply nested with long names, or use UNC paths for source and target, which are either exempt from path length limits or have higher limits — I do not know which.
| [reply] [d/l] |
|
Your problem is almost certainly Windows
I think the problem is almost certainly a typo - but only because, having replicated the OP's file structure (as specified by his code), I can find no problem with it on Windows 7.
OP's script works fine for me, as is.
Either way, it would be interesting to know precisely which it is, but I'm not confident that we'll find out.
Cheers, Rob
| [reply] |
|
| [reply] |