keyongtech


  keyongtech > programmer > 01/2008

 #1  
01-08-08, 11:13 AM
Patrick
Hi all

I try to execute a simple shell script under UNIX/Solaris but run into
a problem with too long path names (see example code below which is
close to reality).

Suppose that the first function call works fine but the second one
fails. The only difference I can see is the length of the filename
which I pass as argument to the function CopySource ().

Are there any restrictions in the length of strings I can pass to cp?
Or what could be the problem?

I tried already to have the arguments split over two lines (masking
LF) but this wasn't the solution.

Any help very appreciated

Patrick

P.S: I'm an experienced programmer but not very familiar with UNIX.


#!/bin/sh
#
##----------------------------------------------------------------------
##CREATE FUNCTION FOR COPYING FILES
##----------------------------------------------------------------------

CopySource () {
##--- Arguments: 1. SourceFile, 2. SourcePath, 3.
TargetPath
cp $2/$1 $3
rc=$?
echo $rc
if [ $rc -eq 0 ]; then
echo "Success: $1 copied"
else
echo "Failed: $1 not copied"
fi
}

##----------------------------------------------------------------------
##COPY FILES
##----------------------------------------------------------------------

##-----------------Copy Source Files ----------------------------
SourceDir=/Slevel1/Slevel2/..../Slevel10/Slevel11
TargetDir=/Tlevel1/Tlevel2/..../Tlevel10/Tlevel11
mkdir $TargetDir

CopySource F_T_A_S_M_T.dat $SourceDir $TargetDir

CopySource File_Two_And_Some_More_Text.dat $SourceDir $TargetDir
 #2  
01-08-08, 12:31 PM
Bill Marcum
On 2008-01-08, Patrick <patrick.matter> wrote:
>> Hi all

>
> I try to execute a simple shell script under UNIX/Solaris but run into
> a problem with too long path names (see example code below which is
> close to reality).
>
> Suppose that the first function call works fine but the second one
> fails. The only difference I can see is the length of the filename
> which I pass as argument to the function CopySource ().
>
> Are there any restrictions in the length of strings I can pass to cp?
> Or what could be the problem?
>

(1) In case a filename or pathname contains spaces, you should quote the
variables.
(2) mkdir will fail if the directory already exists.
[..]
 #3  
01-08-08, 10:12 PM
Scott Lurndal
Patrick <patrick.matter> writes:
>Hi all
>
>I try to execute a simple shell script under UNIX/Solaris but run into
>a problem with too long path names (see example code below which is
>close to reality).


Maximum path length is file-system specific. You must use the
'getconf' command to determine what the maximum path length is
for the filesystem to which your copy is targetted.

scott
Similar Threads
File Names: List Long file Names from Database List of short file names

Hi We have a list of file paths and short file names in our database. We need to loop through them all, picking up the long file name from the file itself and check that...

Converting long file path names to short paths

Hi, How can I convert a very long file path in to a short path with dots (...) in the path name. For example, in VC++ file properties dialog displays long file path with...

Long file names suddenly converted to short file names

I am running Windows XP SP2 and am connecting to a Windows 2003 Server. This morning I opened up a folder on the server and noticed hat all the files in it had been renamed...

Copy problem - is there a utility to search for long path & file names?

I'm trying to copy My Documents to another hard disk. XP Pro tells me about half way throught the copy that it can't copy a file because the name is too long. I think it is...

Problem with long file names

How to find them on my computer and automaticcaly rename them. I have several fils like that, and I don't want to rename them one by one in DOS... this is a mess.


All times are GMT. The time now is 03:43 AM. | Privacy Policy