Windows 10 file search two folders - windows

I'm in document control.
I have to search two folders repeatedly.
Can windows 10 search inside of both folders at the same time?
Glenn. Thanks.

There are two options:
- search common parent folder and include only results from desired paths
- create custom search, which searches only desired paths
Let's say I have this folder structure:
.\temp\A\B\folder1
.\temp\I\J\folder2
.\temp\X\Y\folder3
where each folder contains files named fileX in FolderY.txt
Now I want to search for file1 in folder1 and folder2, but not in any other folders, like folder3
Option 1
Open folder that is common for both subfolders containing searched files. In our example it's folder temp.
And enter this search string: file1 (folder:(temp\A\B\folder1) OR folder:temp\I\J\folder2)
brackets containing OR statement is needed, and brackets around path are optional, if that path does not contain spaces.
This Option is not very optimal if the folder from which you start your search contains many files. Starting this search from C:\ will still search the whole C:\
Option 2
Firstly enter search string including any possible search options, but without folder specification:
Now click Search - Save Search and save the search to a .search-ms file
Open that file in Notepad and close to the end, there will be something like this:
<include path="::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\C:\temp" attributes="1887437183"/>
Duplicate the whole tag as many times as needed, while changing path on each to one, in which you want the search to be done.
Save the file, rename as you like, move to any place you like and use it by double-clicking on it.
This way, only specified locations are searched, which makes the search fast
in this screenshot picture, the search-ms is formatted, which is normally not. It doesn't matter if you save it formatted or minified, or if you format just the Scope element, entering each include on a new line
any search options are also saved to search-ms, like recursive search (Current Folder\All subfolders), date, or file type
you can also use <exclude path= to exclude a path location from search
you can use <include knownFolder="<GUID>" to make locations more generic and portable Known Folder IDs
More about search-ms format

I created a batch file using option 2.
It allows you to specify a search term and then generate and run an .ms-search file.
You must replace the path "C:\Folder01", "D:\Folder01", "E:\Folder01", "F:\Folder01".
#echo off
SETLOCAL enabledelayedexpansion
for /l %%x in (1, 1, 100) do (
set /p searchterm="Enter search: "
(
echo ^<?xml version="1.0"?^>
echo ^<persistedQuery version="1.0"^>
echo ^<viewInfo viewMode="details" iconSize="16"^>
echo ^<sortList^>
echo ^<sort viewField="System.DateModified" direction="descending"/^>
echo ^</sortList^>
echo ^</viewInfo^>
echo ^<query^>
echo ^<conditions^>
echo ^<condition type="leafCondition" property="System.Generic.String" operator="wordmatch" propertyType="string" value="!searchterm!" localeName="en-US"^>
echo ^</condition^>
echo ^</conditions^>
echo ^<kindList^>
echo ^<kind name="item"/^>
echo ^</kindList^>
echo ^<scope^>
echo ^<include path="::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\C:\Folder01" attributes="1887437149"/^>
echo ^<include path="::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\D:\Folder01" attributes="1887437149"/^>
echo ^<include path="::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\E:\Folder01" attributes="1887437149"/^>
echo ^<include path="::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\F:\Folder01" attributes="1887437149"/^>
echo ^</scope^>
echo ^</query^>
echo ^</persistedQuery^>
) > GeneratedMoviesSearch.search-ms
GeneratedMoviesSearch.search-ms
)

Related

Batch File to copy files from one subdirectory to another subdirectory that contains a "_" character

I've been struggling to get this script working and have been doing a lot of searching but can't seem to figure out how to do.
I have a specific directory and this directory contains two additional subdirectories, "User Data" and "a_bcdefg". The first subdirectory name is static but the 2nd subdirectory name is always random characters but always contains a single character at the start then an underscore "_". I am trying to copy all the files from "User Data" into "a_bcdefg" without having to specify the directory since the name is always different.
I've been trying various iterations of the following but can't get it to work:
xcopy /e /c "C:\temp\test\User Data\*.*" "C:\temp\test\*_*"

Rename multiple files with batch windows

I need to rename a group of .pdf files
In the \Source folder I have the files:
bbbbbbbbb-56.pdf
vduysdvss-60.pdf
sdvbdsbvv-80.pdf
I have to rename them in the \Destination folder like this:
11111111-bbbbbbbbb-ggg-hhh-56-dddd.pdf
11111111-vduysdvss-ggg-hhh-60-dddd.pdf
11111111-sdvbdsbvv-ggg-hhh-80-dddd.pdf
so I need to insert some fixed parts:
before the name
in the middle of the name
at the end of the name.
Using the command:
cd \Source
copy "\Source" "\Destination"
cd \Destination
ren *.pdf 11111111-?????????-ggg-hhh???-dddd.*
the result is:
11111111--56-ggg-hhh-dddd.pdf
the bbbbbbbbb string disappears
can you help me?
Thanks
By using the following command Copy the files from Source to Destination :
copy "/Source_folder" "/Destination_folder"
Go in /Destination folder
cd "/Destination_folder"
And then ren the file names by the following command :
ren *.pdf ???-new_filename_part.*
(The question mark (?) is also a wildcard, but it represents a character of the original file name. So, in the syntax, we're using three question marks, which means that the output file name will include the first three characters of the original file (which works as a unique identifier to avoid duplication)
(According to your logic you can change the new filenames by using some RegExpressions or some variables)

Windows batch script: saving a list of selected file to new text file using ECHO

I have provided all the detail and code below, but, the problem is only in the last line.
Background
I am creating a script named, GetSelectedFiles.cmd, whose shortcut is added to Windows' "Send To" context menu. For example, by copying the shortcut of above file to location: c:\users\user\AppData\Roaming\Microsoft\Windows\SendTo.
Purpose:
The goal of that script file is to get the list of selected file names when the user goes to the context menu and selects Send To > GetSelectedFiles.cmd.
Requirement:
1) The the selected file names will be separated by new lines.
2) The list will only contain the bare file name and extension (no path).
3) The list will be a saved inside the same directory as selected files.
4) The list will will be saved in a file whose file name matches the first selected file and has extension of `.selection`.
Example:
Assume you are in directory c:\users\u\. Say this directory has files named: w.txt, x.txt, y.txt, z.txt, with some other files.
User selects those above named 4 files, right clicks and does Send To > GetSelectedFiles.cmd.
After completing the above steps, the directory should have a new file named w.selection and it should contain following lines
w.txt
x.txt
y.txt
z.txt
It is a basic task, but, where I am having problem is the last line, specifically %firstFile% just returns empty. What am I missing?
::::::::::::::::::::::::::::::::::::
:::: Here is the complete code :::::
setlocal EnableDelayedExpansion
:: For new line const
set LF=^
for %%A in (%*) do (
IF NOT DEFINED firstFile (SET firstFile=%%~nxA)
::: This last line is the problem!
echo %%~nxA ^%LF% >> %%~dpA%firstFile%.selection
)

Append part of folder name to all .gz within

I have a folder of data folders with the following structure:
sampleName1-randomNumbers/subfolder1/subfolder2/subfolder3/data1.gz
sampleName1-randomNumbers/subfolder1/subfolder2/subfolder3/data2.gz
sampleName2-randomNumbers/subfolder1/subfolder2/subfolder3/data1.gz
I want to modify all the data.gz within each sample folder by appending the sample name but not the random numbers to get:
sampleName1-randomNumbers/subfolder1/subfolder2/subfolder3/sampleName1_data1.gz
sampleName1-randomNumbers/subfolder1/subfolder2/subfolder3/sampleName1_data2.gz
sampleName2-randomNumbers/subfolder1/subfolder2/subfolder3/sampleName2_data1.gz
It seems like this should be a simple mv for loop but I haven't been able to figure out how to pull part of a folder name using basename.
for i in */Data/Intensities/BaseCalls/*.gz; do mv $i "fastq""/"${i%%-*}"."`basename $i`; done
I couldn't figure out how to make the files stay in their original folder but for my purposes it works to have all the files go to a new folder ("fastq")
I suppose the "sampleName" part doesn't include dashes. In that case, use the standard pattern removal expansion: %%. That is, suppose your full path (relative to directory root) is stored in $path, just do ${path%%-*} to extract the "sampleName" part. Search for %% in the Bash Reference Manual for more details. As a simple example:
> path=sampleName1-randomNumbers/subfolder1/subfolder2/subfolder3/data1.gz
> echo ${path%%-*}
sampleName1
Otherwise, you could also use more advanced substring extraction based on regex. See BashFAQ/100 or Manipulating Strings from the TLDP Advanced Bash Scripting Guide.
Update. Here's the full command to perform the job described, and it is entirely native to the shell:
for file in */Data/Intensities/BaseCalls/*.gz; do
mv "$file" "${file%/*}/${file%%-*}_${file##*/}"
done

Windows batch - concatenate multiple text files into one

I need to create a script, which concatenates multiple text files into one.
I know it's simple to use
type *.txt > merged.txt
But the requirement is to "concatenate files from same day into file day_YYYY-DD-MM.txt" I am a Linux user and Windows batch is hell for me. It's Windows XP.
Windows type command works similarly to UNIX cat.
Example 1: Merge with file names (This will merge file1.csv & file2.csv to create concat.csv)
type file1.csv file2.csv > concat.csv
Example 2: Merge files with pattern (This will merge all files with csv extension and create concat.csv)
When using asterisk(*) to concatenate all files. Please DON'T use same extension for target file(Eg. .csv). There should be some difference in pattern else target file will also be considered in concatenation
type *.csv > concat_csv.txt
At its most basic, concatenating files from a batch file is done with 'copy'.
copy file1.txt + file2.txt + file3.txt concattedfile.txt
In Win 7, navigate to the directory where your text files are. On the command prompt use:
copy *.txt combined.txt
Where combined.txt is the name of the newly created text file.
Place all files need to copied in a separate folder, for ease place them in c drive.
Open Command Prompt - windows>type cmd>select command prompt.
You can see the default directory pointing - Ex : C:[Folder_Name]>.
Change the directory to point to the folder which you have placed files to be copied, using ' cd [Folder_Name] ' command.
After pointing to directory - type 'dir' which shows all the files present in folder, just to make sure everything at place.
Now type : 'copy *.txt [newfile_name].txt' and press enter.
Done!
All the text in individual files will be copied to [newfile_name].txt
I am reiterating some of the other points already made, but including a 3rd example that helps when you have files across folders that you want to concatenate.
Example 1 (files in the same folder):
copy file1.txt+file2.txt+file3.txt file123.txt
Example 2 (files in same folder):
type *.txt > combined.txt
Example 3 (files exist across multiple folders, assumes newfileoutput.txt doesn't exist):
for /D %f in (folderName) DO type %f/filename.txt >> .\newfileoutput.txt
We can use normal CAT command to merge files..
D:> cat *.csv > outputs.csv
cat "input files" > "output files"
This works in PowerShell, which is the Windows preferred shell in current Windows versions, therefore it works. It is also the only version of the answers above to work with large files, where 'type' or 'copy' fails.
Try this:
#echo off
set yyyy=%date:~6,4%
set mm=%date:~3,2%
set dd=%date:~0,2%
set /p temp= "Enter the name of text file: "
FOR /F "tokens=* delims=" %%x in (texto1.txt, texto2.txt, texto3.txt) DO echo %%x >> day_%temp%.txt
This code ask you to set the name of the file after "day_" where you can input the date.
If you want to name your file like the actual date you can do this:
FOR /F "tokens=* delims=" %%x in (texto1.txt, texto2.txt, texto3.txt) DO echo %%x >> day_%yyyy%-%mm%-%dd%.txt
You can do it using type:
type"C:\<Directory containing files>\*.txt"> merged.txt
all the files in the directory will be appendeded to the file merged.txt.
copy is definitely much faster than type - but it sometimes (with large files?) adds a SUB character at the end of the file. So, strictly speaking, it does not simply concatenate the files in the same way as cat in Unix.
So, the correct answer is to use cat - either in something like Git Bash (where it has the same syntax as in Unix), or PowerShell (where it does not).

Resources