Trying to get the files from filepath using java.io.File "File f = new File("//DEV/Test")" in beanshellsampler JMeter configured in Jenkins, when try to get the absolute path, getting only "/Dev/Test". one '/' is missing.
String folderPath = "//Dev/Test";
#oneway
File folder = new File(folderPath);
folder.toAbsolutePath(); //output :: /Dev/Test
#Secondway
Path p1 = Paths.get(foldertoString, new String[0]);
File pathtoFile = p1.toFile();
String[] fn = pathtoFile.list();
// output : path is not correct
It's not missing, / is the root of the Linux file system, there is no need to have an extra slash there.
Also be informed that starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so consider migrating on next available opportunity.
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?
Related
i want to ask for help with opening a file from c# app with associated app.
I tried this:
ProcessStartInfo pi = new ProcessStartInfo(file);
pi.Arguments = Path.GetFileName(file);
pi.UseShellExecute = true;
pi.WorkingDirectory = Path.GetDirectoryName(file);
pi.FileName = file;
pi.Verb = "OPEN";
Process.Start(pi);
or this:
Process.Start(file);
where string file in both examples represents full path to the file trying to open. Now, everything is working well, except the (jpg) images with ACDSee app. Irfanview associations works well, MS office documents too. After trying to open the jpg image associated with acdsee it just runs the acdsee in the notification area and does not open the file.
I discovered, that in the registry CLASSES_ROOT for *.jpg images, there is an ACDSee.JPG value as associated app, and under this key there is in the shell->Open->Command a path:
"C:\Program Files\ACD Systems\ACDSee\ACDSee.exe" /dde
and I thing that this weird /dde is the reason, why i cannot open the file. I realized that in the same reg key shell->Open there is some DDEExec key entry with value [open("%1")]
For Irfan view or other checked app there is not a ddeexec, just the normal command like
"C:\Program Files (x86)\IrfanView\i_view32.exe" "%1"
that can be run from command line after swaping the %1 for file name, but I could not run the command from acdsee entry in the command line :(
So my question is, how can I set up the ProcessStartInfo object to ensure that it will run all the files as it would be in the explorer by doubleclick, the standards and this DDEExec ones? Is there something other like DDEExec that I shoul be aware of?
thanks and sorry for my EN
UPDATE: because this question still gets upvotes, I want to clarify that accepted answer works. I only had problem with old version of ACDSee and not with the Process.Start command or with the jpg extension.
Just write
System.Diagnostics.Process.Start(#"file path");
example
System.Diagnostics.Process.Start(#"C:\foo.jpg");
System.Diagnostics.Process.Start(#"C:\foo.doc");
System.Diagnostics.Process.Start(#"C:\foo.dxf");
...
And shell will run associated program reading it from the registry, like usual double click does.
In .Net Core (as of v2.2) it should be:
new Process
{
StartInfo = new ProcessStartInfo(#"file path")
{
UseShellExecute = true
}
}.Start();
Related github issue can be found here
This is an old thread but just in case anyone comes across it like I did.
pi.FileName needs to be set to the file name (and possibly full path to file ) of the executable you want to use to open your file. The below code works for me to open a video file with VLC.
var path = files[currentIndex].fileName;
var pi = new ProcessStartInfo(path)
{
Arguments = Path.GetFileName(path),
UseShellExecute = true,
WorkingDirectory = Path.GetDirectoryName(path),
FileName = "C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe",
Verb = "OPEN"
};
Process.Start(pi)
Tigran's answer works but will use windows' default application to open your file, so using ProcessStartInfo may be useful if you want to open the file with an application that is not the default.
Why is this check not return true?
String dirpath = getClass().getResource("../util/assets/sounds/").toString();
File dir = new File(dirpath);
System.out.println(dirpath);
System.out.println(dir);
System.out.println(dir.isDirectory());
It returns these:
file:/D:/JAVA/exercises/FX/TasksList/build/classes/taskslist/util/assets/sounds
file:\D:\JAVA\exercises\FX\TasksList\build\classes\taskslist\util\assets\sounds
false
I run it using netbeans IDE as a source code.
getClass().getResource(...) returns a URL, not a file path string. A file path string is needed by the constructor of File.
You can try using the Paths constructor to construct a valid file path from a URI, which you can get from the resource using toUri().
So, this should work:
Files.isDirectory(
Paths.get(
getClass().getResource("../util/assets/sounds/").toUri()
)
)
Or
new File(
getClass().getResource("../util/assets/sounds/").toUri()
).isDirectory();
I haven't got a windows machine to try that on.
Note: If you start packaging your app as jar (as is recommended), then this technique will break. The resource would not be a file, but instead a jar resource. There is no concept of a file directory in relation to a jar resource.
It supposed to be :
String dirpath = getClass().getResource("../util/assets/sounds/").getPath();
instead of:
String dirpath = getClass().getResource("../util/assets/sounds/").toString();
And it will work.
Good evening,
I am currently working on a programm that takes information from a file into a Database, for testing purposes I used to open Testfiles in the classical way via IO:
function reader (file, delimeter)
local f = io.open(file)
for line in f:lines() do
lines[count] = splitty(line, delimeter)
count = count + 1;
end
end
(this part also containes the first part of a splitter)
But in the actual environment, the database programm imediatly moves the file in another directory with a name change to, for example this:
$30$15$2016$09$26$13$27$24$444Z$.Pal.INV.csv
Now I know the directory but I can't really predict the name, so I wanted to know if there might be a way to open files without knowing their name.
(and delete them after reading them)
I had ideas to use a modified link:
local inputFile = "D:\\Directory\\(*all)"
but it failed.
Other aviable information:
The system is until now only planned on Windows PCs.
The directory will always only contain the one file that is to ready, no other files.
You can use the lfs.dir iterator from LuaFileSystem to iterate through the contents of the directory. A small example:
local lfs = require("lfs")
local path = "D:\\Directory\\" -- Your directory path goes here.
for filename in lfs.dir(path) do
print(filename) -- Work with filename, i will just print it
end
If you keep a record of the files you will be able to know which one is the new one. If it is only one file, then it will be easier, you can just check the extension with a string function. From what i remember the iterator includes .. and .. lfs documentation can be found here.
-- directory name and file name should consist of ASCII-7-bit characters only
local dir = [[C:\Temp\New Folder]]
local file = io.popen('dir /b/s/a-d "'..dir..'" 2>nul:'):read"*a":match"%C+"
if not file then
error"No files in this directory"
end
-- print the file name of first file in the directory
print(file) --> C:\Temp\New Folder\New Text Document.txt
I need to read files from a directory with Node.js, The file names will all be some .json How do I use a wildcard for the portion of the file name in node.js?
You can use glob npm for using wildcard file name pattern matching
var glob = require("glob")
// options is optional
glob("DIR_PATH/*.json", options, function (er, files) {
// files is an array of filenames.
// er is an error object or null.
})
Use glob sync when you wants to get list of files in single call synchronously.
var glob = require("glob").sync;
logfileNames = await glob("./logs/*.log");
I am trying to access a resource file from a servlet but getting HTTP Error 500 - access denied:
File file = new File("//warChildFolder//myFile.txt");
InputStream is = new FileInputStream(file); // <--error on this line
I am on google-app-engine.
Any help appreciated!
Google App Engine docs talk about "white listing" a file. Is that in play here?
I also wonder about this:
File file = new File("//warChildFolder//myFile.txt");
Doesn't the leading slash make this an absolute path?
I'd try it like this:
File file = new File("WEB-INF/warChildFolder/myFile.txt");
Make the path relative to the WAR root and be explicit about WEB-INF.
I'm not sure about Google App Engine but in my experience the only solution that works across containers and platforms is to use ServletContext.getRealPath().
new File(servletContext.getRealPath("/WEB-INF/warChildFolder/myFile.txt"));
The spec says: use forward slashes and a leading slash. This gives you platform independence and you're not relying on the process' current directory.
Does it work if you use single path separators?
(updated to use relative paths):
File file = new File("warChildFolder/myFile.txt");
You need to escape the "\" character in Strings, so use "\", but a single "/" is all that is needed.
Update: It may be that the path being processed is not the same as you expect, you can try logging the absolute path of the file (with file.getAbsolutePath()) to check this.
Another thing to check is that the process has read permissions on the folder/file. If you're not on Windows this can be a problem.