7zip command line powershell extract and view txt compressed - powershell

I use the command to extract only the folders containing a specific name, but now I want to know if it is possible to make 7zip extract only .txt files that have at least one word of my choice in them. Like for example
& 'C:\Program Files\7-zip7z.exe' x *.* -o(directory) *.txt (word I want to have inside the .txt e.g. password)
I used this command as an example of what I wanted it to look like, but in reality it only works for extracting just the filename
If you also have another way to do this with compressed files other than 7zip, I will be happy with any help

Related

Robocopy command to transfer files starting with "MY"

My source folder has many text files with different names. I only want to transfer text files that starts with "MY" only.
For example: MY123.txt
How can I filter out those files to send to destination folder using robocopy? My current query as shown below.
robocopy "user\log" "D:\user\log2\files" /MAXAGE:20210401
are you looking for something like this?
robocopy "user\log" "D:\user\log2\files" "MY*" /MAXAGE:20210401
source here and here

how can i distinguish with perl if i have specified an XLSX or a ZIP file

I have a script which takes two parameters on the command line. One should be the name of an ZIP archive, one must be an excel (XSLX) file. Both parameters must be either relative or full quallified.
Ususally I use File::Type to check if a file has the expected format. but for XLSX files the answer is: "application/zip". I know this is right, because XLSX files are zipped, but how can I distinguish if it's a excel file or if the user made a misstake and provided the ZIP Archive as excel.
I also found File::LibMagic, but I can't get it running on Windows.

Extracting Multiple 7z Files Overrides Same Folder

I'm currently working on a project where I take multiple 7z files and extract the contents of these files in a folder named the same way as the 7z file itself. I also apologize if something like this has been answered already; I spent time trying to investigate this issue but I can't seem to find anyone else who has had a similar issue.
For example:
a1.7z -> <targetpath>/a1/<contents within a1.7z>
The following shell line: a1.7z | % {& "C:\Program Files\7-Zip\7z.exe" "x" $_.fullname "-o<targetpath>\a1" -y -r}
Works like a dream, but only for one 7z file. However, whenever I start extracting a second 7z file, it won't create a new folder but instead will continue to add into the same first folder that is created; second folder is never made. When I manually highlight all of the 7z files I want to extract, right click and select "Extract to "*\", it does what I would like it to do but I can't figure out how to script this action. I should also mention that some of the 7z files, when extracted, can contain subfolders of the same name. I'm not sure if this is throwing off the recursion cycle, but I'm assuming this might be the case.
Any help or advice on this topic would be greatly appreciated!
If you get all the .7z files as IOFileInfo objects (Using get-ChildItem) you can use Mathias comment, as one way to do this with the pipeline, but I recommend you put this inside a loop and look for a better way to choose the names of the folders I.e. "NofFolder_$_.BaseName" just in case of more than 1 folder with the same name.
It really depends on the format you want.

How to loop through files and exclude specific file types

So I'm new to powershell development and writing a script that works with zip files. I can zip everything in a folder just fine, but what I'm really trying to do is loop through the directory, if there is a file with a certain extension, so let's say .txt, then it won't zip that file. I know about 3rd party extensions but I don't want to rely on those since I plan on letting other people use these scripts.
Thanks for any input!
There's no need to "loop through" anything; use the -exclude parameter for get-childitem to exclude any file with the .txt extension. Then pass the resulting collection of files to whatever is doing your zipping.
get-childitem -Exclude *.txt

edit filename using command prompt

I have a number of files in a folder, by mistaken in some of files I enter the wrong name
for example :
filename like : abcefxyz.txt while I suppose to enter abcdevwxyz.txt
that is I simply want to replace ef string in filename with devw
how can I do this using command prompt?
please help...
EDITED
I have a thousands of files whose name like : SomethingLongString_OutdoorGames_DateTime.txt
(which I suppose to enter) but
Accidently in some of files, may be hundreds or thousands in number, I have enter SomethingLongString_IndoorGame_DateTime.txt
I simply want to replace IndoorGame string in filename with OutdoorGamestring (precisely saying).
Here SomethingLongString and DateTime strings in filename is different for different file.
I think this example is more helpful to understand my problem...
on windows use
I dont know how to replace some chars with others,but u can rename this way
dirpath> ren abcefxyz.txt abcdevwxyz.txt
DUNNO.. if they are all TXT files then isolate them in a folder.
From there use Advanced Renamer to a file with NO extension
this way you can use 26 letters to rename the bunch.
CMD use would be Ren A* A (1,2,3,4 etc)
or XCOPY a* A using an older computer..
in a batch you could use for # (filename) do (ren) statements
Would this help?