如何使用powershell脚本搜索目录以及根目录

时间:2016-10-18 07:39:44

标签: powershell

cd ("F:\Offcloud\Gossip Girl\Season 01")
Dir | Rename-Item -NewName { $_.Name -replace "%20","" }
Dir | Rename-Item -NewName { $_.Name -replace "%27","" }
Dir | Rename-Item -NewName { $_.Name -replace "a","" }
Dir | Rename-Item -NewName { $_.Name -replace "b","" }
Dir | Rename-Item -NewName { $_.Name -replace "c","" }
Dir | Rename-Item -NewName { $_.Name -replace "d","" }
Dir | Rename-Item -NewName { $_.Name -replace "e","" }
Dir | Rename-Item -NewName { $_.Name -replace "f","" }
Dir | Rename-Item -NewName { $_.Name -replace "g","" }

等...基本上,我想删除除小列表(0123456789x)之外的所有内容。有什么方法可以做到这一点吗?我目前的剧本花了很长时间。另外,如何更改我的脚本以查看所有子目录?

2 个答案:

答案 0 :(得分:1)

您可以使用-Recurse参数搜索目录级别。

$SearchFolder = "F:\Offcloud\Gossip Girl\Season 01"
Get-ChildItem -Path $SearchFolder -Recurse `
    | Rename-Item -NewName { 
        ($_.BaseName -replace "%20|%27|a|b|c|d|e|f|g","") + $_.Extension 
    }

然后,如果您在regex字符串中使用|的OR运算符(-replace),则可以立即替换所有字符串。替换是在BaseName上完成的,<?php get_header( $name ); ?> <div id="content" class="clearfix row"> <div id="main" class="col-sm-8 clearfix" role="main"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article"> <header> <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail( 'wpbs-featured' ); ?></a> <div class="page-header"><h1 class="h2"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1></div> <p class="meta"><?php _e("Posted", "wpbootstrap"); ?> <time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate><?php echo get_the_date('F jS, Y', '','', FALSE); ?></time> <?php _e("by", "wpbootstrap"); ?> <?php the_author_posts_link(); ?> <span class="amp">&</span> <?php _e("filed under", "wpbootstrap"); ?> <?php the_category(', '); ?>.</p> </header> <!-- end article header --> <section class="post_content clearfix"> <?php the_content( __("Read more &raquo;","wpbootstrap") ); ?> </section> <!-- end article section --> <footer> <p class="tags"><?php the_tags('<span class="tags-title">' . __("Tags","wpbootstrap") . ':</span> ', ' ', ''); ?></p> </footer> <!-- end article footer --> </article> <!-- end article --> <?php endwhile; ?> <?php if (function_exists('wp_bootstrap_page_navi')) { // if expirimental feature is active ?> <?php wp_bootstrap_page_navi(); // use the page navi function ?> <?php } else { // if it is disabled, display regular wp prev & next links ?> <nav class="wp-prev-next"> <ul class="pager"> 是没有扩展名的文件名。然后我们简单地将扩展添加到最后。

答案 1 :(得分:0)

使用此命令:

.state('createCase', {
        url: '/createCase?sn',   // bind your query param to URL
        templateUrl: null,
        controller: null,
        data: {
          requireLogin: false
        },