Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > glob in specific directory

Reply
Thread Tools

glob in specific directory

 
 
shumaker@cs.fsu.edu
Guest
Posts: n/a
 
      04-20-2005
I am writing a DTS package task in perl but am having trouble with the
glob statment. Basically I want to take all *.dat files in a certain
directory, read them in line by line and output them to a single output
file. I have to use full path names because I don't run the perl
script from a specific directory, it's run by the sql server. (Unless
someone knows how to set the working directory from the perl script?)

I set mydirectory to the value of a global DTS package variable, which
is a user supplied string
$mydirectory == "M:/Database Files/Import/"

open(OUT,"> ".$mydirectory."outputfilename.txt") or
die "Can't open output file: $!";

The output file is created in $mydirectory with no problem, but the
data isn't getting read in.

The script worked fine with:

while (glob "*.dat")#for each .dat file
{
open(IN,$_); #open the .dat file
.. . .

when it was a regular script being run from the directory, but when I
try to tell it to search a specific directory:

while (glob $mydirectory."*.dat")
{
open(IN,$_); #open the .dat file
.. . .

Nothing is getting written to me output file, and I'm pretty sure it's
something to do with my syntax for the glob or how I'm specifying the
path string.

PS. If my string variable contains single backslash characters instead
of forward slash characters, do the backslashes get treated as escape
sequences, or are escape sequences only interpreted in string literals?

 
Reply With Quote
 
 
 
 
Mark Clements
Guest
Posts: n/a
 
      04-20-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am writing a DTS package task in perl but am having trouble with the
> glob statment. Basically I want to take all *.dat files in a certain
> directory, read them in line by line and output them to a single output
> file. I have to use full path names because I don't run the perl
> script from a specific directory, it's run by the sql server. (Unless
> someone knows how to set the working directory from the perl script?)

chdir?

> I set mydirectory to the value of a global DTS package variable, which
> is a user supplied string
> $mydirectory == "M:/Database Files/Import/"

This isn't an assignment.

Mark
 
Reply With Quote
 
 
 
 
shumaker@cs.fsu.edu
Guest
Posts: n/a
 
      04-20-2005
"This isn't an assignment."

Sorry. I know it's not an assignment, I was just saying it is equal to
that. The actual statement in my code is:

$mydirectory =
$DTSGlobalVariables->Item("adhoc_output_dat_file_directory")->{Value};

But I was trying to avoid posting anything DTS specific for clarity.

It seems to be a problem with confusing glob because of spaces in my
path.

 
Reply With Quote
 
Chris Mattern
Guest
Posts: n/a
 
      04-20-2005
(E-Mail Removed) wrote:

> I am writing a DTS


DTS?

> package task in perl but am having trouble with the
> glob statment. Basically I want to take all *.dat files in a certain
> directory, read them in line by line and output them to a single output
> file. I have to use full path names because I don't run the perl
> script from a specific directory, it's run by the sql server. (Unless
> someone knows how to set the working directory from the perl script?)


Um, you might want to read:

perldoc -f chdir

>
> I set mydirectory to the value of a global


Why global?

> DTS package variable, which
> is a user supplied string


It's a user supplied string run by the SQL server...did you remember
to untaint the variable?

> $mydirectory == "M:/Database Files/Import/"
>
> open(OUT,"> ".$mydirectory."outputfilename.txt") or
> die "Can't open output file: $!";
>
> The output file is created in $mydirectory with no problem, but the
> data isn't getting read in.
>
> The script worked fine with:
>
> while (glob "*.dat")#for each .dat file
> {
> open(IN,$_); #open the .dat file


Why aren't you checking to see if your open worked, like you
did with the output file?

> . . .
>
> when it was a regular script being run from the directory, but when I
> try to tell it to search a specific directory:
>
> while (glob $mydirectory."*.dat")
> {
> open(IN,$_); #open the .dat file
> . . .
>
> Nothing is getting written to me output file, and I'm pretty sure it's
> something to do with my syntax for the glob


No, that's fine.

> or how I'm specifying the
> path string.


Possibly. If you checked your open, you could find out why it's
failing. Have die() report back the name it tried to open as
well.
>
> PS. If my string variable contains single backslash characters instead
> of forward slash characters, do the backslashes get treated as escape
> sequences, or are escape sequences only interpreted in string literals?


Only in string literals.

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
Reply With Quote
 
shumaker@cs.fsu.edu
Guest
Posts: n/a
 
      04-20-2005
Thanks.

I found documentation that glob doesn't work with directory paths that
have spaces in them.

 
Reply With Quote
 
shumaker@cs.fsu.edu
Guest
Posts: n/a
 
      04-20-2005
Just in case someone else needs the solution for making glob work with
a directory name that has spaces:

while (glob ("\Q$mydirectory*.dat") )
{

The \Q is the key.
Note that the string in $mydirectory ends with a / to seperate the
directory from the *.dat filename.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
i have problem with glob.glob() in remotely directory lameck kassana Python 0 02-26-2009 09:05 AM
glob.glob unicode bug or feature Elbert Lev Python 5 08-02-2004 12:09 AM
Question about glob.glob <--newbie Sean Berry Python 3 05-04-2004 05:34 PM
RE: Bug in glob.glob for files w/o extentions in Windows Tim Peters Python 1 12-01-2003 09:22 AM
Bug in glob.glob for files w/o extentions in Windows Georgy Pruss Python 15 12-01-2003 04:04 AM



Advertisments