Win32: File Manipulation

A

AJ

I am trying to build a script to move files between a couple of FTP
servers and I need to rename the files before I transfer them to the
second server. I am able to get them to a network directory without any
problems but I am having trouble manipulating the files once there.
Below is the code snipit I am having trouble with. Anyone have some
insight?

while ($nextname = <\\\\serverName\\shareName\\PTL\\PTL*.txt>) {
#strip off .txt extension store for uses after file has been ftped
(for second rename)
print $nextname "\n";
$basename = $nextname;
print $basename " ->";
$basename =~ s#.*/##;
print $basename " ->";
$dnlname = $basename.".dnl";
print $dnlname "\n";
if ($PickFTP->Put($nextname.dnl)){
if ($PickFTP->Rename($nextname.dnl,$nextname)) {
print LOGfile "$thisDay, $thisMonth $mday, $Year, $hour:$min:$sec -
Transfer of $nextname.txt to PTL server sucessful.\n";
}
}
}

Thanks for your responses.

--AJ
 
J

jue

Hello,

I am sorry but i think that you could not get an answer without a
full-functioning
sniped from your code.

ex.

What (type|module|.*) is $PickFTP?
(maybe this is selfexplained, but not for me... something like
Net::FTP?)
Where is the code which does the rename of your files local?
(so that they could be "put" remote)

There are some more questions which an executable extract form your
script
could answer.
It may help find your problem (by yourself... if not, post again) :)

Thomas
 
P

Paul Lalli

AJ said:
I am trying to build a script to move files between a couple of FTP
servers and I need to rename the files before I transfer them to the
second server. I am able to get them to a network directory without any
problems but I am having trouble manipulating the files once there.

This is an absolutely horrid problem description. What "trouble" are
you having? What exactly is going wrong? What results are you seeing
that you do not desire, or vice versa?
Below is the code snipit I am having trouble with. Anyone have some
insight?

Insight into *what*? You haven't told us what the problem is. You
haven't even told us what the output of the below code is. How are we
supposed to know what is wrong with the code when you haven't told us
what's wrong with the results?
while ($nextname = <\\\\serverName\\shareName\\PTL\\PTL*.txt>) {
#strip off .txt extension store for uses after file has been ftped
(for second rename)
print $nextname "\n";
$basename = $nextname;
print $basename " ->";

I don't believe for a second that that "works", as $basename is a
string, not a filehandle. Is this the "trouble" you were talking
about? Did you get a compiler error here?
$basename =~ s#.*/##;

In the glob, you're using double-backslashes, but here you're searching
for everything up to the last front-slash. Did the files from the glob
really get returned with the front slashes instead? Or is this the
"trouble" you were talking about?
print $basename " ->";

Same thing here. Not valid syntax, unless $basename is a filehandle,
which it's not. You either need a comma or a period operator between
the two strings.
$dnlname = $basename.".dnl";
print $dnlname "\n";

And a third instance.
if ($PickFTP->Put($nextname.dnl)){

Are you not enabling warnings either? This should give you a warning
about an unquoted string "dnl". Always always enable warnings in your
source code! Of course, since you have three compiler errors above
this line, perhaps you don't even get to this line? Regardless,
you're trying to "Put" the string $nextname concatenated with the
string "dnl", rather than the string ".dnl". Is that what you wanted?
Or is this the "trouble" you were talking about?

And wasn't the whole point of the above to get you to $dnlname? Here
you're using the full path, with the original .txt suffix, and sticking
an extra "dnl" (not ".dnl", mind you) onto it. Do you realize that
after doing all that work to get this variable, you then never use it?
Or is that part of the "trouble" you were talking about?
if ($PickFTP->Rename($nextname.dnl,$nextname)) {

Same problem here.

print LOGfile "$thisDay, $thisMonth $mday, $Year, $hour:$min:$sec -
Transfer of $nextname.txt to PTL server sucessful.\n";

Now you're printing out $nextname with an additional .txt on the end?
Why? You never removed the suffix from $nextname.
}
}
}

Thanks for your responses.

You need to do a *lot* of work composing a better posting if you want
better help. At a bare minimum, your post should contain:
A short-but-complete script that *we can run* that demonstrates your
error
Your sample input.
Your desired output.
Your actual output.

Of course, if you actually figured out what those four things are, you
would most likely solve your own problem and not need to make a posting
to begin with. Have you read the Posting Guidelines that are posted to
this group twice a week?

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top