Jump to content

Recommended Posts

i can't get python to run with apache and need this to work badly. .

 

#!/usr/bin/env python

import os

a = "32496"
b = a[2:5]

dirlist = os.listdir("/repo/files/names/ids/" + b + "/")
found = 0

for i in dirlist:
    if "32496" in i:
        os.system("cp -Rf /repo/files/names/ids/496/32496* /new/folder/process-these/")
        found = found + 1
    else:
        pass

if found != 0:
    echo "I found and copied: " + str(found) + " records."
else:
    echo "I didn't find that one. Sorry"

Link to comment
https://forums.phpfreaks.com/topic/126914-convert-python-to-php/
Share on other sites

i am running linux.

 

the code takes the name of a file with no extension and reads the last 3 digits of the input and looks for files named like it in a directory structure. If it finds them it copies them to a different folder.

 

for instance . . .

  • a web form POSTs a user input of "1234567"
  • the scripts looks for any file starting off with the name "1234567" inside of "/repo/files/names/ids/567/"
  • for every file inside the folder that starts with "1234567" it copies to "/new/folder/process-these/" using a simple linux copy tool and an asterisk *

 

does that help at all?

This should do what the Pyhon script did:

<?php
$a = '32496';
$b = substr($a,-3,3);
$i = 0;
foreach (glob('/repo/files/names/ids/' . $b . '/' . $a . '*') as $file) {
      copy($file,'/new/folder/process-these/' . basename($file));
      $i++;
}
if ($i > 0)
    echo "I found and copied: " + $i + " records.<br>";
else
    echo "I didn't find that one. Sorry";
?>

 

Note: untested

 

Ken

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.