Get-ChildItem finds more files than specified by the -Filter - windows-10

I have a folder with xls and xlsx files. A PowerShell script should process only the xls ones so I thought I will use this simple command to get them:
Get-ChildItem $path -File -Filter "*.xls"
but for some reason it also sees the xlsx files.
Why does it behave this way and how can I force it to work as one would expect?

Related

copy/move same name multiple files in different folder

I have multiple files in different folders with the same name and extension. For example: There are 460 folders and each folder has one file with the name of snps.vcf. I want to copy/move these files to one folder and later on, I will do some analysis that I need to do.
I have tried:
find -type f -name "*.vcf" -exec cp {} /home/AWAN/try';'
but this code overwrites the files and only one file remains there in the end.
I have tried rename but I don't know how to select multiple files by find command then rename. Even with the mmv I couldn't find the possible solution.
You need to write an external script and pass it to -exec.
Your script may use mktemp to generate a random file name. Example:
mktemp /your/directory/try-XXX
The XXX part will be replaced by mktemp with a different value for each call.

find a file using find command only in particular directories even though that file is present in other directories

I have a file named pqr.txt This file, is present in many of the subdirectories, but i want to find only the ones whose path is ../../whatever/whatever/pqr/pqr.txt
I am doing this operation with find command using name option but how can i add this constarint that it has to find pqr.txt only in pqr directories?
Also i am passing name parameter as argument from command-line.
find . -name pqr.txt
If you want to find only the pqr.txt that are in a directory named pqr,
you can use the -path option of find:
find . -path '*/pqr/pqr.txt'

How to compare two same name files in different directories using meld (without giving their path)?

I know commands:
To find path of file:
find . -name filename
To compare two files:
meld path_of_file_in_one_dir path_of_file_in_second_dir
I have to compare so many files in different sub directories of a directory, every time I have to first search the path of that file and then use this path with meld, and this I have to for each file.
It would be very easy if i only give names and root directory of that files to meld.
How can I combine meld and find commands so that I can apply it on each file?
If your directory structure is like this say
test_folder
test1
file_to_cmp
test2
file_to_cmp
test3
file_to_cmp
then you can run the following
meld find . -name "file*" or
meld find . -name "file_to_cmp"
This will compare the 3 files for sure.
About more than three file comparing, I doubt meld can do it.

Move all files in specified folder up one directory

I have a program that extracted files to a series of sub-folders each with a "header" sub-folder. For example:
/share/Videos/Godfather.Part.1
/share/Videos/Godfather.Part.1/<packagename>
/share/Videos/Godfather.Part.1/<packagename>/Godfather.avi
/share/Videos/Godfather.Part.2
/share/Videos/Godfather.Part.2/<packagename>
/share/Videos/Godfather.Part.2/<packagename>/Godfather2.avi
I'd like to take the files in the specified folder <packagename> and move them up one directory so that the file structure looks like this:
/share/Videos/Godfather.Part.1
/share/Videos/Godfather.Part.1/Godfather.avi
/share/Videos/Godfather.Part.2
/share/Videos/Godfather.Part.2/Godfather2.avi
How can I accomplish this task in bash command line? Mind you this is an example using 2 folders, I have 100's like this.
Share and enjoy.
for i in `find . -name "*avi"`
do
dest=`dirname $i`
mv $i $dest/..
done

Zip batch command and Excel

I have many excel files that I need zipped into each of their own zip folders. I thought I had this ironed out, but I have co-workers coming back to me saying that they cannot open the excel file because it has become corrupted. I went back and checked the original file, and it opens up just fine. But when I open up the same version of the file that was zipped, I too get the corrupted error. I'm on Office 2010, which is able to repair it, but my co-workers are all Office 2007 which does not seem to be able to fix the file. My batch code is as follows:
for /r %%X in (*.xlsm) do "C:\Program Files\7-Zip\7z.exe" a -tzip "%%~nX" "%%X"
I think you might be using a wrong value as the first parameter to the 7zip executable. According to the documentation on FOR:
%~nI - expands %I to a file name only
And according to the 7zip documentation:
You can use the "a" command with the single letter a. This command stands for 'archive' or 'add'. Use it to put files in an archive. You have to specify the destination archive, and the source files (in that order).
So, using your script with an example file, it seems to me that your command line becomes:
"C:\Program Files\7-Zip\7z.exe" a -tzip "somefile.xlsm" "C:\path\to\somefile.xlsm"
Shouldn't the first parameter have a .zip file extension on the end? So the line is modified to look like this:
for /r %%X in (*.xlsm) do "C:\Program Files\7-Zip\7z.exe" a -tzip "%%~nX.zip" "%%X"
As annoying as it is, file extensions actually mean something in Windows. Your previous line was creating a zip file with the .xlsm extension. When people try opening those files, Excel complains (because it's a zip file; not a .xlsm).
#Echo OFF
PUSHD "C:\Program Files\7-Zip" && (
FOR /R "%CD%" %%# in (*.xlms) DO (7z a -tzip "%%~n#.zip" "%%#")
POPD
)
REM Don't worry about the PUSHD command, the %CD% variable isn't expanded, that's the trick.
Pause&Exit
And you can use the dynamic operator * (asterisk) and 7zip -recursive parameter if you want all together in one file:
7z a -r -tzip "ALL.zip" "*.xlsm"
Sorry guys.
It was a false alarm. Turns out it wasn't all of the files, but only a select few. The files were sectioned out by region, and the only ones that were corrupt were the first region. Why? I can only assume that they were corrupted by my original attempts at making a batch file, as all the other files were zipped with the finished batch and thus didn't have errors. So nothing was wrong with my script. Thanks for the help though.

Resources