copy {
from zipTree(rootDir.getPath() + "/archive.war")
include 'dirAbc/subdir/'
into 'src/dirEfg/subdir/'
includeEmptyDirs = false
}
I am trying to copy a folder and its contents (including subfolders and their contents), from a war file to a local location.
I have almost got what I want. The problem is the above leaves me with the following directory structure:
src/dirEfg/subdir/dirAbc/subdir/
instead of what I want and was expecting:
src/dirEfg/subdir/
What am I doing wrong?
It looks like this is currently not possible out of the box with the current implementation of zipTree in Gradle.
This enhancement is tracked in this ticket.
There are some workarounds you can try as suggested in this post in the Gradle forums.
One of them hints at extracting the zip tree and moving/renaming the contents.
Related
My Process:
For version control, all my files are named with the format "fileName_v#.#"
I keep a folder called 'Live Environment', and as a new version is rolled out, the current file (ex. fileName_v1.0) is removed from 'Live Environment' folder, and the new version (ex. fileName_v2.0) is moved into 'Live Environment'.
My batch script is used to keep all users on the most current version. It works perfect, except with every version I need to go back and update the hard-coded file name in my script to the new file name.
I would like to use a wildcard to search this folder for whatever file is in the 'Live Environment' folder, and then perform the copy function.
Current Code:
::Sets the default install location as the user's desktop
set "DestinationFolder=%userprofile%\desktop"
::Copies and saves file to the user's Desktop
copy /-y "\\myUNCPath\Live Environment\fileName_v*.accdb" "%DestinationFolder%\copiedFile.accdb"
My Issue:
I've hardcoded the "fileName_v#.#.accdb" in for each version so far, and the code executes perfectly. The second I remove the hardcoded file version and add the "*" wildcard, the code errors. The copy function still runs, but simply creates an empty .accdb file on the users desktop, which when used gives the error:
"Unrecognized database format"
At this point I'm overthinking this and making it harder than it needs to be. A set of fresh eyes on the issue would be helpful. Any help would be greatly appreciated!
#aschipfl - that worked! Thanks for the comment.
Simply adding "/b" to the copy line fixed the issue.
copy /-y /b
(For more details see the aschipfl's comment posted below the question).
Directory Structure:
Project1/ABC/file1.txt
I want the above ABC folder moved/renamed to XYZ (without leaving ABC there).
How can I do this using Gradle. Seems like in Gradle: For a right hand person, it's itching your right ear using your left hand, taking it across top of your head.
I have used the following example: but it doesn't do anything:
task renABCToXYZ(type: Copy) << {
copy {
from "Project1"
into "Project1"
include 'ABC'
rename ('ABC', 'XYZ')
}
}
Your task declaration is incorrectly combining the Copy task type and project.copy method, resulting in a task that has nothing to copy and thus never runs. Besides, Copy isn't the right choice for renaming a directory. There is no Gradle API for renaming, but a bit of Groovy code (leveraging Java's File API) will do. Assuming Project1 is the project directory:
task renABCToXYZ {
doLast {
file("ABC").renameTo(file("XYZ"))
}
}
Looking at the bigger picture, it's probably better to add the renaming logic (i.e. the doLast task action) to the task that produces ABC.
With the solution given above you can rename files and folders, you can move files, but you cannot move folders to another destination with renameTo.
For this case you have to use ant.move:
ant.move(file: sourceDir, tofile: targetDir)
Remark: The question is about renaming folders. So the answer above is correct (but the question is a little bit ambiguous). But maybe my answer is helpfull for other users who stumple upon this question and want move move a folder.
Following code will move a file from one directory to another and will rename file
task wb764Jar( type: Jar ) {
doFirst{
copy {
from 'deployment/alpha/workbench_alpha7_64.jnlp'
into 'build/libs/jar_merge/developed/alpha64/JNLP-INF/'
rename('workbench_alpha7_64.jnlp', 'APPLICATION.JNLP')
}
}
baseName = 'WorkbenchMaster7_64'
from files(wbLibsDir + '/jar_merge/developed/alpha64/')
from zipTree("$wbJar.archivePath")
}
I have a problem when trying to upload multiple files to one WinSCP directory, i can manage to copy just one single file, but the problem is that i need to upload many files that are generated by a software, the names are not fixed ones, so i need to make use of wildcards in roder to copy all of them, i have tried many variants on the code, but it all was unsuccessful, the code i am using is:
open "sftp://myserver:MyPass#sfts.us.myserver.com" -hostkey="hostkey"
put "C:\from*.*" "/Myserverfolder/Subfolder/"
exit
This code does actually copy the first alphabetically named file, but it ignores the rest of the files.
Any help with it would be much appreciated
Try this in script
Lcd C:\from
Cd Myserverfolder/Subfolder
Put *
Try and do all manually first so you can see what's going on.
I have troubles with replacing file contents in my current project. I renamed a directory, and a lot of class names has been changed cause of this. A want to rename this classes with netbeans, but I cannot setup the file path pattern well.
The previous directory path was: Test/TestCase under Source Files, and the new path is Test/UnitTest. So I have to rename the TestCase word to UnitTest in my php files.
I tried with *.php, it works (of course it works...), but returns every php file in the project which contains that word, and I don't want to choose from circa half thousand files the right ones. The files of the unit test system could easily contain the TestCase word...
Tried out the following patterns, but they gave empty result:
Test\UnitTest\*.php
*Test\UnitTest\*.php
Test/UnitTest/*.php
*Test/UnitTest/*.php
Test/UnitTest/*
I have not a clue what I do wrong... I tried to search a tutorial for file search patterns but have found only regex patterns and those are definitely not what I was looking for. Can anybody help me?
Lol, I checked it again, and I realized, that I didn't notice the "scope" part last time. In that you can choose the current selection instead of the entire project. So the pattern matches only the file name, not the relative path of the file...
It was so obvious... This is an epic fail, I think I was too tired...
I have a folder with 2508 files (jpg and pdf) in it on my drive. I have a list in a .txt file of about 1000 files which I want to remove from that folder - either by deleting to trash, or removing to another folder.
Is there a utility - or possibly commands I can put into the terminal - which I can use to do this, without manually moving files while looking through my list?
(Context: The list is a list of orphaned image files put out by Dreamweaver - which I want to remove from the images folder of a given site)..
Any help appreciated.
Thanks.
Put this in the terminal:
cat filename-of-list-with-files | xargs rm