2tonejoe Posted October 3, 2008 Share Posted October 3, 2008 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" Quote Link to comment https://forums.phpfreaks.com/topic/126914-convert-python-to-php/ Share on other sites More sharing options...
kenrbnsn Posted October 3, 2008 Share Posted October 3, 2008 For those of us who don't know Python, can you explain what this code snippet is supposed to do? Then we can help you. Ken Quote Link to comment https://forums.phpfreaks.com/topic/126914-convert-python-to-php/#findComment-656469 Share on other sites More sharing options...
JD* Posted October 3, 2008 Share Posted October 3, 2008 Looks like it's trying to find a file called "32496" in /repo/files/names/ids/496 What type of system are you running on? Windows or Linux? Quote Link to comment https://forums.phpfreaks.com/topic/126914-convert-python-to-php/#findComment-656483 Share on other sites More sharing options...
Maq Posted October 3, 2008 Share Posted October 3, 2008 . Quote Link to comment https://forums.phpfreaks.com/topic/126914-convert-python-to-php/#findComment-656488 Share on other sites More sharing options...
2tonejoe Posted October 3, 2008 Author Share Posted October 3, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/126914-convert-python-to-php/#findComment-656498 Share on other sites More sharing options...
kenrbnsn Posted October 3, 2008 Share Posted October 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/126914-convert-python-to-php/#findComment-656503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.