English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hello,

I want to search my entire system and move all .txt files that have "John Smith" in it to C:\johnsfolder\

I want to with this in DOS batch file programming

2007-04-22 20:09:01 · 4 answers · asked by Netiad 2 in Computers & Internet Programming & Design

4 answers

You can do this using the output of the dir command and pipe it through the find command. If the "find" is successful, then it will move the file to your target folder.

Note: this assumes that the text files are unique. If you need to retain the source directory structure in your "johnsfolder" destination, then that's going to take a little more work.

This command is all on one line,
=========

for /f "tokens=*" %i in ('dir *.txt /s /b') do find /i "john" "%i" && move "%i" c:\johnsfolder\

==========
It uses the output of ('dir *.txt /s /b') - a bare listing of all the text files throughout your subdirectories - and pipes it through the "find" command with,

'find /i "john" "%i"

if it finds "john" in a text file, then the command is successful ( &&) and it uses the

move "%i" c:\johnsfolder\

to move the files.

The "tokens" piece and the quotes around "%i" allow the batch to handle long file/directory names and file/directories with spaces in the names.

2007-04-23 13:56:17 · answer #1 · answered by Kevin 7 · 3 0

2

2016-07-23 07:55:18 · answer #2 · answered by Leroy 3 · 0 0

Take Surveys Earn Cash : http://OnlineSurveys.uzaev.com/?UIXd

2016-07-10 03:18:26 · answer #3 · answered by Caroline 3 · 0 0

You can get some help from
http://expert.timecapsuleyahoo.com/

2007-04-22 20:41:22 · answer #4 · answered by Anonymous · 0 2

fedest.com, questions and answers