Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving Files

Status
Not open for further replies.

rottmanja

Programmer
Aug 5, 2008
17
US
I have run into a weird issue with moving files. When attempting to move a file from one directory to another. The move works somewhat.

I have these directories/files:

From: /mnt/fds-phx/docTmp/coded/1.tif
to: /mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814/tmp

The issue that I am facing is, when I try to move from the from directory to the to directory. The file is moved to /mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814 instead of /mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814/tmp

I have no idea why it is completely ignoring the /tmp part of my string.


Here is my current code.

Code:
		# read trans barcode 
		$primer = Util::Util::trim(Util::Util::fileDecode($transFile));
		
		# set transaction folder path
		my $transPath = $wDir . "plSystem/transactions/active/".$primer."/tmp";

			print "Transpath : " . $transPath . "\n"; 
			print "FileName : ".  $transFile . "\n";
			system("cp $transFile $transPath");
 
Just something to try...
Code:
# read trans barcode 
        $primer = Util::Util::trim(Util::Util::fileDecode($transFile));
        
        # set transaction folder path
        my $transPath = $wDir . "plSystem/transactions/active/".$primer."/tmp/";

            print "Transpath : " . $transPath . "\n"; 
            print "FileName : ".  $transFile . "\n";
            system("cp $transFile $transPath");
Notice the final "/" on the $transPath.
 
That is what I originally tired. I have tried every variation of system(mv ...) system(cp ...) that I could think of. And they always end up in the directory above /tmp/
 
put a slash after temp and see if it helps:

blah/blah/temp/

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Here is my updated dated code. Even with the slash after /tmp/ I still have the same issue. The really weird thing is, I can take the out put from my prints and use it on the command line and it works perfectly fine.

Here is my updated code

Code:
		# read trans barcode 
		$primer = Util::Util::trim(Util::Util::fileDecode($transFile));
		
		# set transaction folder path
		my $transPath = $wDir . "plSystem/transactions/active/" . $primer . "/tmp/";
		
		if(-d $transPath){
			print "Transpath : " . $transPath . "\n"; 
			print "FileName : ".  $transFile . "\n";
			system("mv $transFile $transPath");
		}
 
What output do you get from the following?
Code:
            print "Transpath : " . $transPath . "\n"; 
            print "FileName : ".  $transFile . "\n";

Does this help?
Code:
chomp ( $transPath );
 
This is the output I get.

Transpath : /mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814/tmp/

FileName: /mnt/fds-phx/docTmp/coded/1.tif

Adding the chomp does not help anything.
 
How about this?
Code:
system ( "mv \"$transFile\" \"$transPath\"" );

Have you considered using File::Copy?
 
I have tried system ( "mv \"$transFile\" \"$transPath\"" ); previously.

And I have tried using File::Copy. When I use the code below. I get the error couldn't move the file. Is a directory

But the error doesn't make any sense, since I am using abpaths to the file.

Code:
move($transFile,$transPath) or die "couldn't move the file. $!";
 
Do you have write permissions to that directory?

ls -l /mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814/tmp
 
Yep 100% positive that I have write perms to the directory. The thing is, there are other directories in side of the "primer" directory that I have attempted to write to. And it does the exact same thing.

It will write the file to
ls -l /mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814

Instead of
ls -l /mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814/tmp
 
Should be

It will write the file to
/mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814

Instead of
/mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814
 
try a different name other than tmp, like "temp" or "blah", might be something with the name "tmp" that is the problem, although I am not sure what that could be.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
And I have tried using File::Copy. When I use the code below. I get the error couldn't move the file. Is a directory
But the error doesn't make any sense, since I am using abpaths to the file.
move($transFile,$transPath) or die "couldn't move the file. $!";
What is the exact error message you're getting when you use File::Copy? Could it be that /mnt/fds-phx/docTmp/coded/1.tif is a directory?
 
Tried that one to Kevin, I have 9 other directories under the
/mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814 directory that I have tried to write to. And every single one of them does it.

Here is another really weird thing that I just found. If I use the string form of the directory it works fine (example below).

Code:
my $transPath = "/mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814/tmp"

etc.....
 
What is the exact error message you're getting when you use File::Copy? Could it be that /mnt/fds-phx/docTmp/coded/1.tif is a directory?

/mnt/fds-phx/docTmp/coded/1.tif is the absolute path to the file that I want to move. There is no possible way that the 1.tif file is a directory. I can open and view the document.
 
The exact error message is: Is a directory at Lib/PLSParse.pm line 128. Line 128 is where I have
Code:
move($transFile,$transPath) or die "$!";
 
Two possible ideas:

1) Using the output you indicated you received from the two print statements, I'm noticing the length of your 'cp' command is getting upwards into the 115 to 120 character range. On some older versions so *nix and some not-so-old shells, command strings over a given length are truncated. Try making a symbolic link (eg. ln -s src des) that will bridge the "plSystem/transactions/active/" portion of your command. Then within your code use something like
Code:
my $transPath = $wDir . "primer_lnk/" . $primer . "/tmp/";


2) I'm going to guess that your final "/tmp" directory does indeed exist, otherwise you wouldn't have been able to take your output and use it in the command line(more below on this) - however just in case "/tmp" doesn't exist, use this
Code:
my $transPath = $wDir . "primer_lnk/" . $primer . "/tmp/.";
The trailing dot will remove any ambiguity between the possibility of /tmp being a file name or a directory. Using the dot tells the OS that you specifically mean directory. (just for grins, try a if (! -d $transPath) to verify any potential errors at that level)

Getting back to your command working fine on the command line but not in the program, it sounds very reminiscent of a scenario I had in which a command worked in one interface and not another. It turned out that I was using two different shells in each interface. If I had so say which, I'd pick sh and ksh, but wouldn't bet much on it. Either way, there is that remote possibility that when you're calling system(), you could be invoking a different shell.
 
After trying all 3 of your suggestions. It still does the same thing. This has to be one of the most frustrating bugs I have ever dealt with.

On the other hand I can't rule out that system() might be using a different shell. However everything that I have researched I have yet to find a way to determine what shell system() is using and change it.

Here is my most recent updated code.

The directory plsTrans is the symlink that I created.

Code:
		# read trans barcode 
		$primer = Util::Util::trim(Util::Util::fileDecode($transFile));
		# set transaction folder path
		my $transPath = $wDir . "plsTrans/" . $primer . "/tmp/.";
		
		if(-d $transPath){
			print "Transpath : " . $transPath . "\n"; 
			print "FileName : ".  $transFile . "\n";
			
			system("cp $transFile $transPath");
		}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top