O'Monks with your infinite wisdom, I prostrate myself at your feet. I am nothing, I am nothing without you.

I am writing a script to run on a windows device. The special binary files I'm converting to a txt file are in a server, the user has super-user privileges. My problem is that the txt files, which are also saved in the server, are not deleted after using unlink() The purpose of the script:

  • Store all file directories ending with '.special_binary_file' extension
  • At this point the script is forked
  • Iterate through the file directory array and use a special program to convert .special_binary to .txt (this is done using a system command)
  • open the txt file and parse out data
  • delete the txt file
  • After doing some reading I see that unlink() will not work if the file is open or if the user doesn't have superuser privileges, which is not the case for both.

    Could threading the script interfere with the unlink() command?

    I is baffled.
    #!/usr/bin/perl use warnings; use strict; use File::Find; use File::Basename; use Parallel::ForkManager; my $masterDirect = '//server/secret/juice/2012/'; find(\&file_names, $masterDirect); my @files; sub file_names { if( -f && $File::Find::name=~/\.special$/) { push @files, $File::Find::name; } } + my $maxProcs = 14; my $pm = new Parallel::ForkManager($maxProcs); foreach(@files){ my $pid = $pm->start and next; my @name = split /\//, $_; my $id = pop(@name); my @safeID = split / /, $id; my $perlOut = join "/", @name; my $safeDirect = $perlOut.$safeID[0]; #safe is hipaa compliant my $specialCommand = $_; $specialCommand =~ s/\//\\/g; # needs to be windows formatted. I t +ested it $specialCommand = "\"".$specialCommand."\""; my $specialTxtOut = join "\\", @name; $specialTxtOut ="\"".$specialTxtOut."\""; my $companyCommand = "apt-sauce-to-txt -o ".$specialTxtOut." ".$sp +ecialCommand; unless(exists($specialLog{$safeDirect})) { # log file test, not + shown in this truncated script system($companyCommand); # SEND COMMAND TO THE TERMINAL } ##### # # BEGIN TXT PARSING # ##### my $specialTxtFile = $_.".txt"; if ( -e $specialTxtFile ) { open IN, $_.".txt" or die "CANNOT OPEN special.TXT FILE: INSTA +NCE 1\n"; while(my $line=<IN>){ ##### # # PARSING HAPPENS HERE, NOTHING FANCY HERE LADS # ##### } close(IN); # SEE! } unlink $_.".txt"; # I'VE USED $specialTxtFile too, same result $pm->finish; } $pm->wait_all_children;

    Very important: I would like to delete the file in a single pass. That is create, read, delete. I suppose I could wait until the parsing and then delete them all by storing the directories in an array. But each txt file is ~250Mb and there are over 25,000 files that need to be converted. So I don't think the server can take all that data.


    In reply to Unlink not deleting, Threading issue? by pimperator

    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.