我正在尝试将所有名为vol_0000.nii的文件从一个目录复制到另一个目录。我用'*'替换了变量文件名。所有文件(vol_0000.nii)具有相同的名称,但它们位于不同的文件夹中(由'*'表示)。我不确定当它们被复制时它们是否相互替换,因为它们具有相同的cp名称,例如,vol_00001.nii,vol_00002.nii等等。?
cp /Users/dave/biomkr/dat/*/rs/orig/vol_0000.nii /Users/dave/Documents/MIT_Har_stu/rsfmri
答案 0 :(得分:1)
这样的事情应该完成这项工作,使用与你在问题中提到的类似的编号行为。
register = Library()
def inplace_js(context, activate_inplaceedit=True, toolbar=False):
request = context['request']
request.inplace_js_rendered = True
return {
'STATIC_URL': get_static_url(),
'ADMIN_MEDIA_PREFIX': get_admin_static_url(),
'activate_inplaceedit': activate_inplaceedit,
'auto_save': json.dumps(inplace_settings.INPLACEEDIT_AUTO_SAVE),
'event': inplace_settings.INPLACEEDIT_EVENT,
'disable_click': json.dumps(inplace_settings.INPLACEEDIT_DISABLE_CLICK),
'toolbar': toolbar,
'enable_class': inplace_settings.INPLACE_ENABLE_CLASS,
'success_text': inplace_settings.INPLACEEDIT_SUCCESS_TEXT,
'unsaved_changes': inplace_settings.INPLACEEDIT_UNSAVED_TEXT,
'inplace_get_field_url': inplace_settings.INPLACE_GET_FIELD_URL or reverse('inplace_get_field'),
'inplace_save_url': inplace_settings.INPLACE_SAVE_URL or reverse('inplace_save'),
'field_types': inplace_settings.INPLACE_FIELD_TYPES,
'focus_when_editing': json.dumps(inplace_settings.INPLACE_FOCUS_WHEN_EDITING),
'inplace_js_extra': getattr(request, 'inplace_js_extra', '')
}
register.inclusion_tag("inplaceeditform/inplace_js.html", takes_context=True)(inplace_js)
def inplace_css(context, toolbar=False):
request = context['request']
request.inplace_css_rendered = True
return {
'STATIC_URL': get_static_url(),
'ADMIN_MEDIA_PREFIX': get_admin_static_url(),
'toolbar': toolbar,
'inplace_js_extra': getattr(request, 'inplace_css_extra', '')
}
register.inclusion_tag("inplaceeditform/inplace_css.html", takes_context=True)(inplace_css)
def inplace_static(context):
return {
'STATIC_URL': get_static_url(),
'ADMIN_MEDIA_PREFIX': get_admin_static_url(),
'toolbar': False,
'request': context['request']
}
register.inclusion_tag("inplaceeditform/inplace_static.html", takes_context=True)(inplace_static)
#to old django versions
def inplace_media(context):
return inplace_static(context)
register.inclusion_tag("inplaceeditform/inplace_static.html", takes_context=True)(inplace_media)
def inplace_toolbar(context):
return {
'STATIC_URL': get_static_url(),
'ADMIN_MEDIA_PREFIX': get_admin_static_url(),
'toolbar': True,
'request': context['request']
}
register.inclusion_tag("inplaceeditform/inplace_static.html", takes_context=True)(inplace_toolbar)
class InplaceEditNode(RenderWithArgsAndKwargsNode):
def prepare_context(self, args, kwargs, context):
expression_to_show = args[0]
tokens_to_show = expression_to_show.split('|')
obj_field_name, filters_to_show = tokens_to_show[0], '|'.join(tokens_to_show[1:])
obj_field_name_split = obj_field_name.split(".")
obj_context = '.'.join(obj_field_name_split[:-1])
field_name = obj_field_name_split[-1]
obj = Variable(obj_context).resolve(context)
adaptor = kwargs.get('adaptor', None)
class_adaptor = get_adaptor_class(adaptor, obj, field_name)
request = context.get('request')
config = class_adaptor.get_config(request, **kwargs)
adaptor_field = class_adaptor(request, obj, field_name,
filters_to_show,
config)
context = {
'adaptor_field': adaptor_field,
}
return context
@register.tag
def inplace_edit(parser, token):
args, kwargs = parse_args_kwargs(parser, token)
return InplaceEditNode(args, kwargs, 'inplaceeditform/inplace_edit.html')
@register.tag(name='eval')
def do_eval(parser, token):
"Usage: {% eval %}1 + 1{% endeval %}"
nodelist = parser.parse(('endeval',))
class EvalNode(template.Node):
def render(self, context):
return template.Template(nodelist.render(context)).render(template.Context(context))
parser.delete_first_token()
return EvalNode()
另一种选择是根据原始glob中替换#!/bin/bash
i=0
for src in /Users/dave/biomkr/dat/*/rs/orig/vol_0000.nii
do
dest=$(basename "$src")
dest=${dest/.nii/_$i.nii}
cp "$src" "/Users/dave/Documents/MIT_Har_stu/rsfmri/$dest"
let i++
done
的目录名创建一个子目录,我们可以通过一点string replacement获得。
*