Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Filesearch

Posted on 2011-09-07
10
330 Views
Last Modified: 2012-05-12
Hi,

I need to filter out a directory for certain files and put these files into another directory to be able to search for a string in it. I tried textcrawler but it gets stuck since there are to many folders/files.

So what I would like to do is find a decent way to:
1.look for files with name x.config
2.grab them together and put them on another location, however, the folder in which they were should be displayed since all files are x.config and I need to make distinction between them
3.look for a string within these config-files and display this in a word/excel (this textcrawler can do fine)

Thanks for your input.
0
Comment
Question by:janhoedt
  • 5
  • 5
10 Comments
 
LVL 53

Expert Comment

by:Bill Prew
ID: 36495891
Not sure exactly what you are after, but if you are just moving the files to search them, then why not do it all at once?  Perhaps something like:

findstr /S "searchstring" c:\base\x.config

~bp
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 36495919
But, if you really want to use textcrawler on an extract set of files, you should be able to use XCOPY, and do something like:

xcopy "c:\basedir\x.config" "d:\destdir" /S /I

~bp
0
 

Author Comment

by:janhoedt
ID: 36495926
Just a way to find web.config files in an IIS-directory. Because we need to scan the results (web.config) for a certain string (what can be done with textcrawler), I would like to copy all the web.configs into another location but there the folder should be created in which original folder it was (for example site1\web.config, site2\web.config etc.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:janhoedt
ID: 36495927
Just a way to find web.config files in an IIS-directory. Because we need to scan the results (web.config) for a certain string (what can be done with textcrawler), I would like to copy all the web.configs into another location but there the folder should be created in which original folder it was (for example site1\web.config, site2\web.config etc.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 36495939
Okay, xcopy with /S should preserve the folder structure.

~bp
0
 

Author Comment

by:janhoedt
ID: 36496065
I'd need only the top folder from which it is copied, now it copies the whole structure.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 36496080
Can you provide an example?  Like if the source had:

c:\dir1\dir2\dir3\dir4\web.config

where do you want that file copied to?

~bp
0
 

Author Comment

by:janhoedt
ID: 36496167
Ok, this is an example:

c:\dir1\dir2\dir3\web.config

To

c:\temp\dir1\web.config
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 36499214
Okay, I think this should get the job done, let me know what questions you have.  It basically works through each subfolder of the main directory in the outer FOR loop.  Then under each of those looks for any web.config file, and copies it to a directory as you wanted.

@echo off
set BaseDir=c:\base
set DestDir=c:\dest

for /D %%A in ("%BaseDir%\*") do (
  for /F "tokens=*" %%B in ('dir /b /a-d /s "%%~A\web.config"') do (
    if not exist "%DestDir%\%%~nA\" md "%DestDir%\%%~nA"
    copy "%%~B" "%DestDir%\%%~nA"
  )
)

Open in new window

~bp
0
 

Author Closing Comment

by:janhoedt
ID: 36504668
Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question