How to get the directory path in groovy - groovy

I want to store file in my_application/PdfReports directory ,i am writing the code to store in the file which is in my_application/grails-app/domain/com/my_company/my_application/reports/ReportExporter.groovy .
So how to get the path my_application/PdfReportsv to store files.

If you are deploying the web-app as a war, then I'm not sure the path my_application/PdfReports makes any sense.
The war file (and exploded war folder) will be the contents of your web-app folder, with related grails stuff inside the WEB-INF folder
Why not use a custom absolute path which you can define in your Config.groovy file
Or, to get the real disk based path for your web-application, you could do something like:
String webAppPath = new File( servletContext.getRealPath( '/index.gsp' ) ).parentFile.absolutePath
from inside a controller

Related

Python - working with unkown directory name versions

I'm using python to download an application from a content distribution network. The application downloads as self extract file cabinet. When executed it creates a directory using a version naming format. For example app-version2/../app.exe, Thus I cannot rely on the folder name as it may change in the future. I'm trying to find the best way to work with the content inside the folder without depending on the actual folder name.
My idea was to rename the folder using os.listdir() and then os.rename(app-version2, myapp) This would work but is not automated. What would be the best automated method to find a folder name that contains version numbers and change that to something more static?
Assuming you want to find the path of the directory which begins with app, you can accomplish this using pathlib.Path:
from pathlib import Path
app_path = next(Path().glob('app*'))
This will give you the path to the first file or directory in your current directory whose name begins with "app".

When the DLL file which include in Additional Dependencies under child floder,How can I find it

I Want Put those DLL files under a child folder.
the system is Win7 later.
like there is an opencv_world300d.dll , i need move it into my working directory (its ./),but i want put it under child folder( i.e. ./DLL/) .
Does anyone Know about this ?
The link specified describes DLL search order on windows.
You can copy the opencv_world300d.dll in a sub-folder ( /DLL) but then you have to modify PATH environment variable to include new directory.

Node js. Writing directory to the archive, without path to this directory

Got some task, it is not hard, but i have some trouble.
Maybe someone already has similar problem.
My task is writing to zip archive some folder, with files and other folders in it with using NodeJS
I try to use AdmZip pakage
folder project structure:
var AdmZip = require('adm-zip');
let Archive = new AdmZip();
Archive.addLocalFolder('Archive/filesFolder', '');
Archive.writeZip('Archive/newArchive.zip);
I must get archive with 'filesFolder', instead i get archive with 'Archive' folder and in it i have 'filesFolder'.
If anybody know, how to record only target folder, and not the sequence of a way folders?
What happens is that you are providing Archive/filesFolder as value to writeZip and that means include in the zip Archive folder and inside that include filesFolder.
For testing purpose change the value of writeZip() to just filesFolder.zip and it should zip content of Archive as filesFolder.zip in current working directory. See below (you can copy/paste the bit of code and run it and it should work).
var zip = new AdmZip();
// I don't know why you provided a second argument to below, I removed it
// There was nothing about it in the documentation.
zip.addLocalFolder('./Archive');
//rename the value of the following to just filesFolder.zip
zip.writeZip('filesFolder.zip');
The above should output the content of Archive to the current working directory as filesFolder.zip
I did mention this in my comment and your commend seem to indicate that you have path issue, so try the above script.

Change nodejs temporary directory

I want to make file upload using nodejs, but fs.rename() cannot move a file between two different disks/partitions, I don't want to copy uploaded file from temporary directory.
I want to change temporary directory so fs.rename() will work.
how can i do that? thanks!
The module responsible for that is formidable, and you can set uploadDir, as per the README:
form.uploadDir = "/my/dir";
Sets the directory for placing file uploads in. You can move them
later on using fs.rename(). The default is os.tmpDir().

what is the right format of -adaptresourcefilenames in ProGuard

I have an application JAR file I would like to obfuscate using ProGuard. It contains "AppName\resources" folder and several "ClassName.properties" files in it.
What is the right format of -adaptresourcefilenames option in my config file to adapt the properties files to classes?
The option -adaptresourcefilenames expects the resource files names to start at the same root directory level as the class names. E.g., it can rename mypackage/MyClass.properties (without any directory prefix) corresponding to
the obfuscated name of mypackage/MyClass.class (also without any directory prefix).
In this case, you could work on the unzipped application, specifying the input and output directories so the relative paths correspond again:
-injars input(!AppName/resources/**)
-outjars output
-injars input/AppName/resources
-outjars output/AppName/resources

Resources