I am writing a program to upgrade a firmware using a flash drive. I need to upgrade the Kernel with the image present in the flash device. But I am not getting any idea of how to find a file with zimage file extension in a directory.
I am new to Qt and Linux. So I dont know whether it is possible to find the file with particular format. Can anyone help on this.
Thanks in advance.
There's no general way to access the OS search indexing services on the whole filesystem in Qt. So if that's what you want then an OS-specific solution like what #BЈовић offered would be necessary.
(Note: I actually tend to prefer it when a program makes me point explicitly to where something is, instead of searching the whole filesystem...but even better if it can notice when the necessary file is in the same directory as the executable.)
Anyway...if you know the directory you want to search in, then the QDir abstraction will let you set up a filter and enumerate filenames that match that filter in the directory:
QDir dir (zimagePath);
QStringList filters;
filters << "*.zimage";
foreach (QString file, dir.entryList(filters, QDir::Files)) {
// ...
}
You can read over the QDir docs for more ways of looking at it.
You can execute next script using system(), and parse the output :
#!/bin/bash
find / -name '*.zimage' | grep .zimage > /tmp/zimage_files.txt
Take a note that the above script is going to search all files and all paths, and put the output to /tmp/zimage_files.txt. If you need something different, you need to modify it a bit.
Related
I would like to know how do I open a file with a specific extension
Inside the downloads folder. I try this:
set downloads to "~/Downloads"
set fileExtension to ("pkg")
open every file of downloads whose name extension is fileExtension
I know I could use:
do shell script "open ~/Downloads/blabla.pkg"
and this would work fine but with every update the file changes its name and this would not be interesting to me.
thanks advance!
While do shell script can use a string for a path, AppleScript itself has limited file handling abilities, so you need to tell it to use something that does, such as the Finder or System Events. A file specifier (such as alias, file, or application scripting terms such as folder or disk item) also needs to be used to differentiate a file item from a regular string (such as a POSIX path). Depending on the application used, there may be other differences from the shell, such as tilde expansion, so the StandardAdditions scripting addition provides paths to common locations:
set fileExtension to ("pkg")
tell application "System Events"
repeat with anItem in (get every file of (path to downloads folder) whose name extension is fileExtension)
open anItem
end repeat
end tell
Also note that using the filter reference form “whose” only works with application objects, and not regular lists or records. AppleScriptObjC also has access to Cocoa methods, so you can use the NSWorkSpace or NSFileManager classes, although going that route tends to get a bit more verbose.
I want to get all the files of type A*.txt present in current directory via C++ code. My OS is *Nix system. Also, I want to get the names of such files.
Please suggest how can this be done.
I tried using system command but system doesn't return anything apart a integer which says if command was executed properly or not.
Thanks
There are basically three ways you can go about this.
One is to use basically what you tried before, but using the popen function, which allows you to read the output of the command(s) you run.
The second solution is to use e.g. opendir and readdir or scandir to manually filter and find the files you look for.
The third and easiest way is to use the glob function.
There is actually a fourth way as well, one which is platform independent and more C++-ish than the above methods: Using the Boost filesystem library.
Currently I'm developing a project that should do the thing described above on Windows. I have the idea to recurcively go through all user's drives and collect all information on then, but it seems to be really time consuming. So is there a better way to do such thing (maybe to use OS's index file or NTFS MFT)?
I use C++/Qt.
You can search for any of the many code examples for this and use one.
The library finctions which you use FindFirstFile and FindNextFile are optimized and will go firectly to the FAT. They are coded by microsoft & I doubt that there is a faster way.
Btw, what do mean by "filtered by the text line"? Do you mean you want only filenames matching a certain pattern (use teh above) or files containing a string?
I want to make a program that moves certain named folders (and all files contained) from directory A to directory B. It was suggested to code in C++. So I was wondering if anyone knew of a simple way to do this, if they could give me a link, and if anyone know's where it's possible to set the directories as variables that can be loaded from a text file. I'm asking this question, because I want to basically have all my program settings and whatnot from the appdata folder since I move between computers alot, be easily transferable.
settings.txt (This is an example of what I mean.)
fldrget = (Folder Name)
fldrdir = (Path to Folder)
fldrplc = (Folder Destination)
Would creating an xml document be a better idea as far as the txt document goes?
Additional Information: OS: Windows(XP, Vista, 7) and I'd like to make this a GUI, but as I'm not familiar with any C language, I'll settle for basics first if anyone can give me a push in the right direction.
Can you provide a bit more information? Are you wanting to write a console application or a GUI? What platform are you targeting? You could use the Win32 API, Boost, Qt, Wx, or a number of others.
You may want to look into using PowerShell. It is much more friendly for a new comer and built-in to Windows 7 and freely available for Windows XP. Just do a google search for moving a directory using PowerShell to get started
Apparently this supposed to be possible. For example opening and operating on a file with NOTEPAD, or HxD. But aren't they all text files...how would one specify which text editor to open the file and operate on the file with using the WINDOWS API. It is certainly not in "CreateFile".
Hopefully I'm understanding your question... The easiest way to do this is to launch the desired editor and pass the filename as an argument, rather than "invoking" the file (which will launch the default program associated with the file type).
For example, notepad.exe mytextfile.txt or gvim.exe mytextfile.txt.
If the editor is not on your %PATH%, you'll need to use a full path file name.
What are you trying to do, exactly? You could:
Maintain a list of editors that you expect to be installed and have entries for in the system's PATH (bad idea)
Have an editor/editors that you want to use, query the Windows registry to find the installation path of the editors (using RegGetValue), and launch the editor with CreateProcess) (a little better idea)
Query the registry to get the default editor for a given file type and then launch that editor using CreateProcess. (best idea)
But it all depends on what your goal is really.
Edit based on requirements
So, just so we're on the same page, from C++, you want to:
Take a command line parameter to your C++ application (filename)
Open that file in an arbitrary editor
Detect when the user has made changes to that file
Operate on the file contents
Is that correct?
If so, you could:
Use Boost libs to compute a CRC for the current data in the file
Launch an editor using one of the methods I initially described
Stick in a tight loop and sleep so you don't chew up resources while the initially computed CRC matches one calculated every iteration of the loop
Of course, there are all kinds of issues that you'd have to deal with (that's just a super simple way of describing the algorithm I might use), such as:
What happens if the user doesn't change the file?
What happens if the file isn't found?
I'm sure that there are a number of different methods of doing this, but this is the easiest method that I can think of at the moment (while still being able to be fairly certain of the changes).
Disclaimer: I haven't implemented something like this, so I might be completely off base ;)
Are you looking for the ShellExecute() or ShellExecuteEx() APIs on Windows? They'll launch whatever program is registered for a file (generally based on the filename extention).