Extract file with 7Zlib command line into directory - c++

I would like to extract a file with 7za.exe (Link to download 7za.exe command line).
I can extract with the commands e or x, but my files are extracted in the current file.
It is a mess, that is why I want to specify the destination directory.
I already tried this command but it won't work :
7za e myZipFile.zip myDestinationFolder
7za x myZipFile.zip myDestinationFolder
It says No files to process

Finally I've just find the way to extract my zipped files in another folder !
By default 7z extract files into the current folder...
This allow to extract the files in the c:\soft folder :
7z e archive.zip -oc:\soft *.cpp -r
The trick is that we have to attache the command -o directly before our destination directory ! So beware : no space between the command -o and our destination directory path.

Related

Grep with regex from file in bash script without inclusion of more folders

I have a file containing various paths such as:
/home/user/Desktop/Bash/file1.txt
/home/user/Desktop/Bash/file2.txt
/home/user/Desktop/Bash/file3.txt
/home/user/Desktop/Bash/moreFiles/anotherFile.txt
/home/user/Desktop/text/prettyFile.txt
And I receive a input from user that contains the directory, such as:
/home/user/Desktop/Bash/
And I usually save this expression into regex to find all the files in the directory by grep. However, if the folder has more folders, it includes them as well, but I want to only include the files in the directory that was entered by the user. My desired output is should be this:
/home/user/Desktop/Bash/file1.txt
/home/user/Desktop/Bash/file2.txt
/home/user/Desktop/Bash/file3.txt
But it keeps including
/home/user/Desktop/Bash/moreFiles/anotherFile.txt
which I don't want and I need to do it inside a bash script.
You can use this grep command to get just the files directly under given path skipping sub-directories:
s='/home/user/Desktop/Bash/'
grep -E "$s[^/]+/?$" file
/home/user/Desktop/Bash/file1.txt
/home/user/Desktop/Bash/file2.txt
/home/user/Desktop/Bash/file3.txt

Regex add file extension

I'm looking for the regular expression to find all the files in a folder (and its subfolders) that do not have an extension and add the extension .mp3 to these files only (i.e. the files which already have the extension should not get an additional one)?
For example:
test is made into test.mp3
test1.mp3 remains as it is
An additional problem I have is that some of my file names have spaces.
So far I use the following expression for the first part (with maxdepth specifying the depth in terms of folder structure I want to have):
find . -maxdepth 1 ! -name "*.*" -o -name ".*[^.]*"
I cannot work out how to do the adding of the .mp3 extension.
The below find command would recursively rename(adding .mp3 as extension to those files) the files which don't have any extension.
find . ! -name *.* -type f -exec mv {} {}.mp3 \;
The following command won't modify any files as long as -nono argument is present:
rename -v -nono 's{.+(\.mp3)?\Z}{.mp3}i' *
rename(1) utility is provided by "rename" package on Debian.

Regex to add an extension to a directory full of files

I am new to regular expressions.
I have many irregularly numbered ascii files with no extension: g000554, g000556, g000558, g000561, g000563 ... g001979 etc
I would like to type a regex at the terminal (or in a short script) to add a .dat to all of these files.
So I would like to change them to become: g000554.dat, g000556.dat, g000558.dat, g000561.dat, g000563.dat ... g001979.dat etc
p.s. Sorry I should have provided more info: by terminal I meant a mac terminal and I cannot use the 'rename' command.
I think you're using a linux system. So i provide a bash solution. It works only if your files starts with g and there is no other files in that directory except the files you want to rename.
for i in g*; do mv "$i" "$i.dat"; done
The below would add .dat extension to all the files present in the current directory,
for i in *; do mv "$i" "$i.dat"; done

How to find specific text string in nested tar.gz archives?

How to find specific text string in source code files packed into nested .tar.gz archives, packed inside anothe rar archive(48MB)? (on Windows 7) I tried to use LookDisk, but it hangs and crash. Is it possible to find use system findstr utility, and what's regular expressions for this? Or with other search utility, that do not need installation(portable).
Based on a SuperUser answer this example batch file searches multiple .tar.gz archive files (specified on the command line) and outputs the filename of the .tar.gz containing specified string.
It does this without outputting any files to disk.
It is dependant on 7-Zip, you can use a portable version of this - it doesn't need to be "installed" - but be available.
Change the value of the variable SEARCHSTR (currently hell) to the string you want to search for.
I can't see any obvious or easy way of returning the filename of the file containing the text inside the archive.
#echo off
setlocal enabledelayedexpansion
set SEARCHSTR=hell
rem Ensure 7z.exe is in your path or in current directory... ie. set PATH=%PATH%;C:\Program Files\7-Zip
rem Loop through all commandline args - the tar.gz files
for %%i in (%*) do (
rem Extract without an intermediate .tar
7z x "%%i" -so | 7z x -si -ttar -so | findstr /C:"%SEARCHSTR%"
if "!ERRORLEVEL!" == "0" (
set FOUNDIN=%%i
rem Exit after we find the first occurrence.
goto found
)
)
:notfound
echo Unable to locate search string "%SEARCHSTR%" in specified files.
goto end
:found
echo Found search string "%SEARCHSTR%" in "%FOUNDIN%".
:end
Edit 1 - Using self contained / portable 7-Zip
Download the official 7-Zip Command Line Version one listed on the Official 7-Zip Download page extract and use 7za.exe it's a self-contained command line version of 7-Zip, meaning you won't need any extra files just 7za.exe.
You will need to change the two occurrences of 7z to 7za to use this version.
So the line:
7z x "%%i" -so | 7z x -si -ttar -so | findstr /C:"%SEARCHSTR%"
Changes to:
7za x "%%i" -so | 7za x -si -ttar -so | findstr /C:"%SEARCHSTR%"

Xcode 4 file input/output, command line tool C++

I'm trying to figure out where to save multiple .txt files so that i can have a command line tool project in Xcode read directly in from them while running it.
I understand that Xcode compiles everything to a folder, DerivedData, which i have saved in the same location as my source code for each project respectively.
can i save multiple .txt files anywhere in the DerivedData folder or include it in the build settings and phases so that when i run the command line tool i can type the name of a file, it will read in from that file.
By default the compiled/linked binary will look into its own directory for files.
For example, my binaries are at ProjectName/Build/Products/Debug/ and therefore it will look for files from that dir.
You can use relative path from that folder to the outside.
Or, you can create a symbolic link to another directory (on Terminal):
ln -s source_dir target_file
target_file must be located in the same directory as your binary. And you can reference the other files like "target_file/file1.txt", etc.