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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a directory using environmental vars

Status
Not open for further replies.
Dec 17, 2002
41
US
back again, still lost.

I am creating txt files and storing the data from an oracle database in them. I can create the files fine, as long as I point to the right directory. I want to create the directory, in the same manner I create the file and name it the date of the backup. Is this possible? Below is the code that doesn't work (it does create the txt file,but no directory), but I think it will give you an idea of what I'm trying to do. Thanks.

my $table_Name = param('table_name');
my $date = $ENV{'DATE_LOCAL'};

my $sql = qq{SELECT * FROM "$table_Name" };

#Prepare the SQL and execute.

my $sth = $dbh->prepare( $sql );
$sth->execute();

#Fetch output rows into array, plus prepare a
#print formatter for the results.

while ( my @String = $sth->fetchrow_array) {

#Print out the result
my $data="$table_Name.txt";
open(DAT,">>../DPRIS Backup Data Files/$date/$data") || die("Cannot Open File");
print DAT "'";
print DAT join "', '", @String;
print DAT "'";
print DAT "\n";
close(DAT);

}
 
Check out the system call I added and see if that works.

Nathan

while ( my @String = $sth->fetchrow_array) {

#Print out the result
my $data="$table_Name.txt";
system("mkdir ../DPRIS Backup Data Files/$date");
open(DAT,">>../DPRIS Backup Data Files/$date/$data") || die("Cannot Open File");
print DAT "'";
print DAT join "', '", @String;
print DAT "'";
print DAT "\n";
close(DAT);

}
 
Nathan,

Tried, no dice, made sense to me but not to my machine. It just creates the file in the DPRIS Data Backup Files directory.

Matt
 
Nathan

Still can't get it to name the directory the same as the environmental variable DATE_LOCAL.
But here's a partial solution:

while ( my @String = $sth->fetchrow_array) {

#Print out the result
my $data="$table_Name.txt";
mkdir ../DPRIS Backup Data Files/folder_name");
open(DAT,">>../DPRIS Backup Data Files/folder_name/$data") || die("Cannot Open File");
print DAT "'";
print DAT join "', '", @String;
print DAT "'";
print DAT "\n";
close(DAT);

}

 
while ( my @String = $sth->fetchrow_array) {

#Print out the result
my $data="$table_Name.txt";
system("cd ../DPRIS Backup Data Files; mkdir $date");
open(DAT,">>../DPRIS Backup Data Files/$date/$data") || die("Cannot Open File");
print DAT "'";
print DAT join "', '", @String;
print DAT "'";
print DAT "\n";
close(DAT);

}
 
I think I found the problem. The ENV variable DATE_LOCAL names the folder dayofweek, date-month-year hr:min:sec PST. Windows file naming conventions won't allow a : in the name. So it throws an error. Can you alter an environmental variable? I actually don't want the time anyway, with multiple tables it would create a seperate directory for each table because they are backed up at different times, not what I'm looking for. I just want the day, date-month-year, any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top