简体   繁体   English

除一个子文件夹外,所有子文件夹中都需要文件

[英]Need files in all subfolders except one

I wrote the below condition to get all *.js files from a folder and its subfolder. 我编写了以下条件,以从文件夹及其子文件夹中获取所有*.js文件。 I wrote the below command to get the list: 我写了下面的命令来获取列表:

c:/svn/myfolder/**/*.js

"myfolder" has 4 sub folders a, b, c, d in it and i want to get list of .js files only from three of the subfolders and skip checking the subfolder 'c' . "myfolder"有4个子文件夹a, b, c, d ,我只想从三个子文件夹中获取.js文件列表,并跳过对子文件夹'c'检查。

Currently it returns all .js files as i put myfolder/**/*.js 目前,当我放置myfolder/**/*.js .js它将返回所有.js文件

Ruby's glob syntax borrows from regex. Ruby的glob语法来自regex。 You can specify a range of characters using brackets. 您可以使用方括号指定字符范围。

Dir['c:/svn/myfolder/[abd]/*.js']

This will include a, b, and d but not c. 这将包括a,b和d,但不包括c。 You can also negate: 您还可以否定:

Dir['c:/svn/myfolder/[^c]/*.js']

This will include all but c 这将包括c以外的所有内容

See http://ruby-doc.org/core-2.1.3/Dir.html#method-c-glob for more info on Ruby globs. 有关Ruby glob的更多信息,请参见http://ruby-doc.org/core-2.1.3/Dir.html#method-c-glob

You can use Dir glob to get all the files and directories as a list. 您可以使用Dir glob来获取所有文件和目录的列表。 To accomplish this with regex do: 要使用正则表达式完成此操作,请执行以下操作:

Dir.glob(File.join(['c:/svn/myfolder', '*[^excluded_folder]', '**', '*.js']))

The *[^excluded_folder] includes everything but excluded_folder . *[^excluded_folder]包含除exclude_folder之外的所有内容。

Keeping the ** as part of your path will grab files from the current directory path it's placed at as well as all subdirectories. **保留为路径的一部分将从其所在的当前目录路径以及所有子目录中获取文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM