Jump to content

file batch for windows ....


vbk!!!

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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...