Code that outputs the 23rd to 29th characters of the file name and outputs the entire file name when there are not 7 characters

Asked 2 years ago, Updated 2 years ago, 32 views

For example, the file name '181001161609_00001_1AE_AAAABAA' AAAAABAA. If this part is not 7 digits, I would like to know the code that prints the full file name '181001161609_00001_1AE_AAAABAA'. I'm trying to make it because I need it at work, but it's too hard. Please help me.

code

2022-09-21 16:57

1 Answers

Can you install PHP? Then...

<?php

// Import all files/directories where this php file resides
$files = scandir(__DIR__);

// Take out useless things
unset($files[0]);
unset($files[1]);

// For all files/directories
foreach ($files as $file) {

    // Keep all file names separate
    $fullFileName = $file;

    // Name.If it is an extension, leave only the name part
    if (preg_match('/.*\..*/', */', $file))
        $file = preg_replace('/(.*)\..*/', */', '$1', $file);

    // If you clear the first 23 characters of the name and the rest is less than 7 characters, output the full filename
    if (strlen(substr($file, 23)) !== 7)
        echo $fullFileName."\n";
}

?>

The key is (1) reading the current directory (2) regex, so I think you can port it enough if you use Python. (If you find a good macro program in the first place and do well, you can do this without a single line of coding.))

Anyway, I'm a PHP villain. MAKE PHP GREAT AGAIN


2022-09-21 16:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.