在编写环境的时候,最新版的代码中,包含了较多的文件和文件夹的操作,比如下面的代码片段
self.robot_id = p.loadSDF(os.path.join(sdf_loc, "kuka_with_wsg2.kuka_with_gripper"))[0]
id = p.loadSDF(os.path.join('models/small_object_models', obj, '1/model.sdf'))[0]
self.objects_list: List = os.listdir(ignition_models_path)
new_folder='small_object_models'
if not os.path.exists(new_folder):
os.mkdir(new_folder)
else:
try:
shutil.rmtree(new_folder)
except:
print('Delete folder failed!')
os.mkdir(new_folder)
if len(small_length_list)>=2:
shutil.copytree(os.path.join(target_dir,model),os.path.join(new_folder,model))
for model in models:
shutil.copyfile(os.path.join(target_dir,model,'1/materials/textures/texture.png'),os.path.join(target_dir,model,'1/meshes/texture.png'))
虽然文件和文件夹的操作可能纷繁复杂,但是花样再多,也都能在 Python文件和文件夹操作整理 - 古月居 (guyuehome.com) 这篇文章中找到姿势最好的写法和以不变应万变的编程手法。
第三方账号登入
QQ 微博 微信