Hi. I am having a problem with my script checking to see if a file exists, and if so, deleteing it.

The script is run from the D: drive of the computername John. It is checking in the c:\daily directory for a file name daily_count_by_userid_and_domain.xls. This is just part of my existing script, since the rest of it works. Below is my code.

What I am doing wrong? How can I ensure that this file exists at the start of the script and that it will be deleted? I'm very sorry to have to ask what should be such an easy question.

#!d:\perl\bin use File::Copy; my $filename ='daily_count_by_userid_and_domain.xls'; my $path = '\\\\John\\c$\\daily\\'; my $nfile = '_daily_count_by_userid_and_domain.xls'; my $test = 'outputfile.txt'; ($Second, $Minute, $Hour, $DayOfMonth, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time); my $real = $Year + 1900; my ($d,$m) = (localtime)[3,4]; my $date = sprintf("%02d%02d",++$m,$d,); my $npath = '\\\\Bob\\scripts\\security\\public\\'; my $complete = '$path$filename'; opendir (HOLDING, 'C:\daily'); chdir 'C:\daily'; @asci = glob ('*.xls'); foreach $asci (@asci) { if ($asci =~ /$asci/) system ("del $asci"); } system("\"C:\\Program Files\\Microsoft Office\\Office\\MSACCESS.EXE\" d:\\imas_security\\imas_security.mdb /x auto_update"); open(OUT, ">>$test"); copy ("$path$filename", "$npath$real$date$nfile"); closedir(HOLDING); close (OUT);

MHTIA.


In reply to Searching for a file, confirming that it exists, then deleting it by OnTheEdge

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.