Jump to content
Sign in to follow this  
vbk!!!

file batch for windows ....

Recommended Posts

Hello,

 

I am trying to follow the crowd tutorial of Guillaume Fradin. During this, he is using one of his tool, a filebatch tool to convert bvh files in bclip/cmd files.

I tried the hda but it seems there is a compatibility problem between Linux and Windows. I am on Win7 ...

Newbi onPython programming,I am now trying to modify this script to make it work properly on WIndows but I am unable to make something working :(

 

here is the original script :

import os
import re
import sys

def start(node):
    for file in file_list(node):
        launch_cmd_on_file(node, file)

def get_nb_files(node):
    nb_files = len(file_list(node))
    node.parm('nb_files').set(nb_files)
    

def file_list(node):
    dir = node.evalParm('directory')
    pattern = node.evalParm('pattern')
    return pattern_matching_file_list(dir, pattern)
    

def launch_cmd_on_file(node, file):
    cmd = node.evalParm('cmd')
    dir = '/'.join(file.split('/')[0:-1])
    cmd = "cd "+dir+';'+cmd+' '+file+';\n'
    print cmd
    os.system(cmd)

def pattern_matching_file_list(dir, pattern):
    list = []
    for root, dirs, files in os.walk(dir):
        for file in files:
            if re.search(pattern, file) is not None:
                list.append(os.path.join(root,file))

    return list

On Windows I find a problem with the os.system(cmd) line : I don't think mutiple command works on windows ( or not this way at least).

The pattern_matching_file_list function give slash/backslash issue.

 

After some failed tests, I am focusing on a specific directory to understand what is going on.

Here is the modified code :

import os
import re
import sys

def start(node):
    for file in file_list(node):
        launch_cmd_on_file(node, file)

def get_nb_files(node):
    nb_files = len(file_list(node))
    node.parm('nb_files').set(nb_files)
    

def file_list(node):
    dir = node.evalParm('directory')
    pattern = node.evalParm('pattern')
    return pattern_matching_file_list(dir, pattern)
    

def launch_cmd_on_file(node, file):
    cmd = node.evalParm('cmd')
#    dir = node.evalParm('directory')+'/'.join(file.split('_')[0:-1])
    dir = node.evalParm('directory')
    cmdb = "cd "+ dir
    cmdc = cmd +' '+ file
    print cmdb +' '+ cmdc
    os.system(cmdb)
    os.system(cmdc)

def pattern_matching_file_list(dir, pattern):
    list = []
    for root, dirs, files in os.walk(dir):
        for file in files:
            if re.search(pattern, file) is not None:
                list.append(os.path.join(file))

    return list

with this code mcbiovision returns it's unable to open .bvh file for reading.

 

 

the print cmdb +' '+ cmdc  return line likes this : cd D:/MOCAP/CMU/01/ mcbiovision 01_14.bvh

 

Of course, if I tape theses 2 commands in a the houdini command line tool, it works as excepted.

 

Why theses 2 commands works when I tape them but don't work when it execute via python ?

Could it be beacause of  the 2 os.system() ? If yes, how can I use one os.system for 2 commands on Windows ?

 

Thanks for your help

 

Vincent

 

Share this post


Link to post
Share on other sites

os.chdir() instead of os.system() with cd.

 

and complete path for the mcbiovision.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×