Search Files of a directory in another directory - command-line

Things Required Step-By Step:
List all files/items in Directory/Sub-Directory.(e.g. List files/items of DirA)
Search All Listed Files in another Directory (e.g. Search files/items of DirA in DirB)
output the result using windows search. (e.g. each file/item is individually searched in DirB and results displayed in individual search Windows )
Required in a .bat file (Command Line script) or suggest a tool which helps me perform this.

You can check for file and subfolder names from one folder in another folder like this (if that's what you mean by "search all listed files in another directory"):
for %%f in ("C:\folder1\*") do (
if exist "C:\folder2\%%~nxf" echo %%~nxf exists in C:\folder2
)
It's not clear to me what you mean by "output the result using Windows Search", though.

Related

.gitignore all except one specific file (via a full/fuller file path)

The Goal:
How to use .gitignore to exclude all folders & files except PowerShell $Profile?
The answer should help expand the current exception file list to more files in other subfolders. If possible, reduce wildcards to minimum, and use as specific as possible (full/fuller file path). Why? For instance, Book1.xlsx may exist in multiple subfolders but I want to be able to choose only the specific desired subfolders.
Thanks in advance!
Current status:
On Windows 10 (not Linux Distros):
git init initiated on top level directory C:\. [Please don't suggest to start from other subfolders. Just remain with C:\, as I will include more files to the exception list]
C:\.gitignore containing the below:
# Ignore All
/*
# Exception List [eg. PowerShell's $Profile (please use FULL/FULLER FILE PATH, if possible)]
!.gitignore
!Microsoft.PowerShell_profile.ps1
!Users/John/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1
!Users\John\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
!C:/Users/John/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1
!C:\Users\John\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
With the above codes, git status successfully returned only .gitignore as 1 untracked file. Microsoft.PowerShell_profile.ps1 remained missing from untrack listing.
I've tried alternative ways (wildcard, partial subfolder name with pattern, etc) but all failed to return the fuller file path PowerShell $Profile.

How to copy folder (Via Command prompt) which is contain a space in the name?

if i copy without space (Name Folder),
example:
xcopy /E C:\Test\SQL G:\SQL
this copy all content of my folder, Fine!
i dont know how to copy folder if name contain a space, With "xcopy" command.
i found many reviews about space in command prompt and show me solutions like
c:\>xcopy /E "c:\Documents\SQL Server Management\" "G:\SQL\"
but doesn't work for me.
if I copy a folder where the name contains spaces, the result is: Invalid number of parameters...
Any can help me ?
Tnhks
You should report the error message you are receiving, what happened when you executed he command (if anything) and what you expected to happen.
Your problem is that copy requires a filemask to know which files you require to be copied.
c:>xcopy /E "c:\Documents\SQL Server Management*.*" "G:\SQL\"
specifies that all files with all extensions be copied. The quotes are required to specify "paths\containing spaces" as xcopy (or any other command has no way of reading your mind and can't be certain of what c:\Documents\SQL Server Management\ G:\SQL\ means - is it 'copy c:\Documents\SQL to "Server Management\ G:\SQL\"' or 'copy "c:\Documents\SQL Server" to "Management\ G:\SQL\"' or are sume of what appear to be arguments strays data or what?

7zip / winrar command to extract a folder with path intact to specific folder but excluding parent source path

example
There is a file "sample.rar".
Folder structure is: "rising\dawn\ and here there are many (folders1, folders2 and file1, file2)" in this archive.
i have used following command
7z.exe x "sample.rar" "rising\dawn\*" -oi:\delete
The result is:
all files and folders in "rising\dawn\" are extracted to "i:\delete" folder but the empty parent folders "rising\dawn\" are also created in destination folder.
e.g. destination looks:
i:\delete\rising\dawn\folder1\file1.bmp
i:\delete\rising\dawn\folder2\subfolder
i:\delete\rising\dawn\file1.txt
i:\delete\rising\dawn\file2.txt
i don't want "rising\dawn\" empty folders to be created but the folder structure there onwards must be as is in the archive.
i want the result:
i:\delete\folder1\file1.bmp
i:\delete\folder2\subfolder
i:\delete\file1.txt
i:\delete\file2.txt
at last i found a way out solution. thanks to the winrar support. i have accepted it as an answer below.
if you find the question useful don't forget to click the up-vote button.
Finally this gave me the result.
Thanks to winrar support.
rar x -ep1 sample.rar rising\dawn\* d:\e\delete\
i have tried other answers given here, this is the only correct answer.
don't forget to upvote.
You can extract the archive normally and
1) move the lower level folder/files to where you would like it, then
2) remove the extra top level archive folders.
Code to do so will depend on the exact task.
Using e command instead of x and add -r option works well.
Like this:
7z.exe e -r "sample.rar" "rising\dawn\*" -oi:\delete
My executable version is "7-Zip [64] 9.20 2010-11-18",
And the platform is Windows 8.1.
This command line eliminates unnecessary parent folders and preserves the hierarchy of folders.
You need to use the e command rather than the x command:
7z.exe e "sample.rar" "scholar\update\*" -oi:\delete
Using e instead of x means 7zip will extract all matching files into the same folder (as specified via the -so switch, or the current directory if this isn't specified) rather than preserving the folder structure from inside the archive.

Find folder name from a specific location

How can I find a folder from a specific location using command prompt.
eg:- I want to search files from desktop and there are around 10 files that contains the name starting from A and i want locations of all such file with file name.
I know it can be done using find commnad but I am unable to write the correct code for it.
Thanks for the help
you can find all files from a directory and sub directories that start with 'a' using this:
dir /b /s a*.*

I want to prompt a user for the first 5 characters of a file then have it search for the files

I'm trying to write a script that will prompt the user for the first 5 charters of a file name then have it search the directories for any files that start with that. Then I want it to check to see if a folder is created with the file names and if not create one then move the files there. But if there is a directory for it already then to just move the files too the folder.
Break it down step by step:
"prompt the user for the first 5 characters of a file name" -- you can use the shell read command to get the data. Try a simple shell script:
#!/bin/bash
read foo
echo "foo = $foo"
"if a folder is created with the file names" -- you can use find to see if a file exists. for example:
find . -name abcde\*
"But if there is a directory for it already then to just move the files too the folder." -- the command mkdir takes a -p option so that, if the directory already exists, it won't do anything.