I am writing a grunt-contrib-clean script and want to delete all the sub-directories in a directory excluding two directories. Following is the directory structure:
/resources/nls/ar
/resources/nls/ar-AE
/resources/nls/ca
/resources/nls/ca-ES
/resources/nls/en
/resources/nls/en-US
/resources/nls/localeElements.js
and so on for all the locales.
I want to keep only the en, en-US directories and the file localeElements.js. I am using the following Grunt script. The single file in "nls" folder is not deleted as desired. But it deletes all the folders inside including the en & en-US folders which I don't want. Please guide and help.
clean: {
postBuildSizeReduction: [
'!../resources/nls/en/**',
'!../resources/nls/en-US/**',
'../resources/nls/*/'
]
}
Change the order of the directories listed, so that the deletions come first, followed by the exclusions.
clean: {
postBuildSizeReduction: [
'../resources/nls/',
'!../resources/nls/en',
'!../resources/nls/en-US'
]
}
Related
I'm using grunt to search all my .js files in order to create documentation and I want it to search all the files inside web/assets/js/, so I made it like this:
ngdocs: {
all: ['web/assets/js/*.js']
},
However I found out that this doesn't include the .js files inside the subfolders.
Is there a way to make it look inside those subfolders or do I have to specify all of them in the gruntfile?
To also include the .js files inside the subfolders add double glob stars ** to your glob pattern as shown in the following snippet:
ngdocs: {
all: ['web/assets/js/**/*.js']
},
An excerpt from the Globbing patterns section of the grunt documentation reads:
All most people need to know is that foo/*.js will match all files ending with .js in the foo/ subdirectory, but foo/**/*.js will match all files ending with .js in the foo/ subdirectory and all of its subdirectories.
Thanks to #RobC answer, I found out that in order to get all subfolders .js files, had to do it like this:
ngdocs: {
all: ['web/assets/js/*/*.js']
},
I'm not sure why the double glob stars ** don't work for me, but anyway, this is the answer to my problem.
I have the following structure
I want to copy only folders, subfolders and files, which are located in "_bearbeitet".
I am trying it with the following options
--archive --hard-links --ignore-errors --force --exclude=* --include=/_bearbeitet
You have your rules in the wrong order, and your glob is too general.
Try this:
--include=/_bearbeitet --exclude='/*'
So altogether:
rsync -aH --ignore-errors --force --include=/_bearbeitet --exclude='/*' $src $dest
The rule is that, for each file, rsync will use the first include/exclude rule that matches, and will include anything that matches no rule.
So, first list what you want to include: /_barbeitet matches the named directory at the top level only.
Then list what you want to exclude after: /* matches all files and directories at the top level only. Note that * on it's own would exclude all files and directories anywhere, including files and directories inside an explicitly included directory.
You should also take care to put quotes around * in patterns or else the shell will expand them before calling rsync, which is not what you want.
I have a task where I would like to run and operate on the files in a current directory.
What I have so far is:
grunt.registerTask('getfiles', function() {
var files = fs.readdirSync(process.cwd());
console.log(files);
});
The problem is, it only ever outputs the top level files.
My directory looks like this:
-node-modules
-content
-file1
-file2
-Gruntfile.js
-package.json
And it currently outputs:
[ '.git',
'.gitignore',
'Gruntfile.js',
'content',
'node_modules',
'package.json' ]
But I would like it to output:
['file1,
'file2]
when I run grunt inside the content directory.
How would I go about doing this?
Update:
I just realised that I can do:
grunt --base .
Some additional information:
The desired outcome is to be able to rename specific files with a command like:
grunt rename file1 file2
I thought this would be a no-brainer, but I can't seem to figure it out. Let's say I want to unzip all zip files in a directory and place the results in another directory. All files follow the pattern region_*.zip, where * is some id.
raster/region_%.tif: zip/region_%.zip
unzip -d raster $<
My problem: How do I include this operation in my all directive?
# Does not work
all: raster_region_%.tif
Make always works backward from the target you want to create, back to the source files (in this case zip files).
Make has to be told, somehow, what the target you want to create is. It can't just intuit that out of thin air.
In this case, if you want to build a .tif file for each zip file you need to first get a list of all the zip files then convert them into the target files:
ZIPFILES := $(wildcard zip/region_*.zip)
TARGETS := $(patsubst zip/region_%.zip,raster/region_%.tif,$(ZIPFILES))
all: $(TARGETS)
I would like rsync to exclude all directories that contain a file with a specific name, say ".rsync-exclude", independent of the contents of the ".rsync-exclude" file.
If the file ".rsync-exclude" contained just "*", I could use rsync -r SRC DEST --filter='dir-merge,- .rsync-exclude'.
However, the directory should be excluded independent of the contents of the ".rsync-exclude" file (it should at least be possible to leave the ".rsync-exclude" file empty).
Any ideas?
rsync does not support this (at least the manpage does not mention anything), but you can do it in two steps:
run find to find the .rsync-exclude files
pipe this list to --exclude-from (or use a temporary file)
--exclude-from=FILE
This option is related to the --exclude option, but it specifies a FILE that contains exclude patterns
(one per line). Blank lines in the file and lines starting with ';' or '#' are ignored. If FILE is -,
the list will be read from standard input.
alternatively, if you do not mind to put something in the files, you can use:
-F The -F option is a shorthand for adding two --filter rules to your command. The first time it is used
is a shorthand for this rule:
--filter='dir-merge /.rsync-filter'
This tells rsync to look for per-directory .rsync-filter files that have been sprinkled through the
hierarchy and use their rules to filter the files in the transfer. If -F is repeated, it is a short-
hand for this rule:
--filter='exclude .rsync-filter'
This filters out the .rsync-filter files themselves from the transfer.
See the FILTER RULES section for detailed information on how these options work.
Old question, but I had the same one..
You can add the following filter:
--filter="dir-merge,n- .rsync-exclude"
Now you can place a .rsync-exclude file in any folder and write the names of the files and folders you want to exclude line by line. for example:
#.rsync-exclude file
folderYouWantToExclude
allFilesThatStartWithXY*
someSpecialImage.png
So you can use patterns in there too.
What you can't do is:
#.rsync-exclude file
folder/someFileYouWantToExlude
Hope it helps! Cheers
rsync -avz --exclude 'dir' /source /destination