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

Removing characters and change \ to \\ in a string

Status
Not open for further replies.

NavMen

Vendor
Jul 6, 2004
35
NL
Hi,

I’m trying to get information from the SQL server and with this information I like to create directories on a Windows Server share.

The following script works fine except the creation of the directories on the Windows Server share is not working?

--------------------------------------------------------
#!/usr/local/bin/perl -w
use strict;
use Errno;
use Getopt::Std;
use Win32::ODBC;
use Time::Local;

my $SHARE = "\\\\Server1\\Test";
my $db="";

$db = new Win32::ODBC("infoDB");
if ($db)
{
writeLogFile($out, "$dsn allocated\n") if ($out);
}

if ( !$db->Sql("SELECT * FROM repsrv WHERE (targetSrv = 'Server1')"))
{
while ($db->FetchRow())
{
($id, $localSrv, $sourceDir, $targetDir) = $db->Data("NO", "localSrv", "sourceDir", "targetDir");
#print "$id, localSrv='$localSrv', sourceDir='$sourceDir', targetDir='$targetDir'\n";
print "$SHARE\\$localSrv\\$sourceDir\n";
system("mkdir $SHARE\\$localSrv\\$sourceDir ");
}

}


$db->Close();

-------------------------------------------------------
The output from print is:

\\Server1\Test\DellSrv1\F:\TimeTest
\\Server1\Test\HPSrv1\D:\Data\Groups
\\Server1\Test\IBMSrv1\E:\Home\Users

The error is “The specified path is invalid.”
I’m using the system("mkdir $SHARE\\$localSrv\\$sourceDir "); to create the directory. And output of $sourceDir= D:\Data\Groups

My feeling is that the : and the single \ is generating my problem, if yes how can I remove the : and create a double \\ in $sourceDir string.

I don’t now how to do this

Thanks,

Navmen


 
You could use single forward slashes instead of escaping the backslashes with backslashes.

For substitution
$sourceDir=~s/:/\\\\/; #the : may need escaping

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top