Windows Batch Script for finding string within files with a specified date and copying to a new directory





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am trying to do the following



FORFILES /S /M *.* /P <DIR> /D <MM/DD/YYYY>

FINDSTR /S /M /I <%CRITERIA%>

DO ECHO <FILE>

XCOPY /Y <FILE> <DIR>


My original script is this



set /p search="Enter Search Criteria: "
set /p date="Enter Date (MM/DD/YYYY): "

if not exist "C:%search%" mkdir C:%search%

for /f %%a in ('findstr /s /m /i "%search%" "C:log*.txt"') do echo %%a & xcopy /y "%%a" "C:%search%"

@pause




But it searches every single file on the server which can take a while, I'm hoping by reducing the list to the specified date I can focus the search.










share|improve this question

























  • Open a Command Prompt window, enter RoboCopy /? and read the output.

    – Compo
    Jan 4 at 6:23











  • %search% is a file? If not, then add an extra after %search%.

    – double-beep
    Jan 4 at 14:39













  • @Compo i wasnt able to use robocopy in this instance as i couldnt figure out how to initiate it in the DO and also reference the %%a. If possible i know robocopy would be better as i get a nice clean output. i was going to try xxcopy but it appears to have its limitations also

    – David Zammit
    Jan 6 at 23:08











  • @double-beep %search% is referencing the users input for Criteria, this is any string really that could be within the files, example we have *.txt files and on the first line is a reference number AA-XXXXX, so if i type in that criteria it searches all the files that are related to it.

    – David Zammit
    Jan 6 at 23:13


















1















I am trying to do the following



FORFILES /S /M *.* /P <DIR> /D <MM/DD/YYYY>

FINDSTR /S /M /I <%CRITERIA%>

DO ECHO <FILE>

XCOPY /Y <FILE> <DIR>


My original script is this



set /p search="Enter Search Criteria: "
set /p date="Enter Date (MM/DD/YYYY): "

if not exist "C:%search%" mkdir C:%search%

for /f %%a in ('findstr /s /m /i "%search%" "C:log*.txt"') do echo %%a & xcopy /y "%%a" "C:%search%"

@pause




But it searches every single file on the server which can take a while, I'm hoping by reducing the list to the specified date I can focus the search.










share|improve this question

























  • Open a Command Prompt window, enter RoboCopy /? and read the output.

    – Compo
    Jan 4 at 6:23











  • %search% is a file? If not, then add an extra after %search%.

    – double-beep
    Jan 4 at 14:39













  • @Compo i wasnt able to use robocopy in this instance as i couldnt figure out how to initiate it in the DO and also reference the %%a. If possible i know robocopy would be better as i get a nice clean output. i was going to try xxcopy but it appears to have its limitations also

    – David Zammit
    Jan 6 at 23:08











  • @double-beep %search% is referencing the users input for Criteria, this is any string really that could be within the files, example we have *.txt files and on the first line is a reference number AA-XXXXX, so if i type in that criteria it searches all the files that are related to it.

    – David Zammit
    Jan 6 at 23:13














1












1








1


2






I am trying to do the following



FORFILES /S /M *.* /P <DIR> /D <MM/DD/YYYY>

FINDSTR /S /M /I <%CRITERIA%>

DO ECHO <FILE>

XCOPY /Y <FILE> <DIR>


My original script is this



set /p search="Enter Search Criteria: "
set /p date="Enter Date (MM/DD/YYYY): "

if not exist "C:%search%" mkdir C:%search%

for /f %%a in ('findstr /s /m /i "%search%" "C:log*.txt"') do echo %%a & xcopy /y "%%a" "C:%search%"

@pause




But it searches every single file on the server which can take a while, I'm hoping by reducing the list to the specified date I can focus the search.










share|improve this question
















I am trying to do the following



FORFILES /S /M *.* /P <DIR> /D <MM/DD/YYYY>

FINDSTR /S /M /I <%CRITERIA%>

DO ECHO <FILE>

XCOPY /Y <FILE> <DIR>


My original script is this



set /p search="Enter Search Criteria: "
set /p date="Enter Date (MM/DD/YYYY): "

if not exist "C:%search%" mkdir C:%search%

for /f %%a in ('findstr /s /m /i "%search%" "C:log*.txt"') do echo %%a & xcopy /y "%%a" "C:%search%"

@pause




But it searches every single file on the server which can take a while, I'm hoping by reducing the list to the specified date I can focus the search.







batch-file






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 6:17









Compo

17.2k31027




17.2k31027










asked Jan 4 at 5:04









David ZammitDavid Zammit

92




92













  • Open a Command Prompt window, enter RoboCopy /? and read the output.

    – Compo
    Jan 4 at 6:23











  • %search% is a file? If not, then add an extra after %search%.

    – double-beep
    Jan 4 at 14:39













  • @Compo i wasnt able to use robocopy in this instance as i couldnt figure out how to initiate it in the DO and also reference the %%a. If possible i know robocopy would be better as i get a nice clean output. i was going to try xxcopy but it appears to have its limitations also

    – David Zammit
    Jan 6 at 23:08











  • @double-beep %search% is referencing the users input for Criteria, this is any string really that could be within the files, example we have *.txt files and on the first line is a reference number AA-XXXXX, so if i type in that criteria it searches all the files that are related to it.

    – David Zammit
    Jan 6 at 23:13



















  • Open a Command Prompt window, enter RoboCopy /? and read the output.

    – Compo
    Jan 4 at 6:23











  • %search% is a file? If not, then add an extra after %search%.

    – double-beep
    Jan 4 at 14:39













  • @Compo i wasnt able to use robocopy in this instance as i couldnt figure out how to initiate it in the DO and also reference the %%a. If possible i know robocopy would be better as i get a nice clean output. i was going to try xxcopy but it appears to have its limitations also

    – David Zammit
    Jan 6 at 23:08











  • @double-beep %search% is referencing the users input for Criteria, this is any string really that could be within the files, example we have *.txt files and on the first line is a reference number AA-XXXXX, so if i type in that criteria it searches all the files that are related to it.

    – David Zammit
    Jan 6 at 23:13

















Open a Command Prompt window, enter RoboCopy /? and read the output.

– Compo
Jan 4 at 6:23





Open a Command Prompt window, enter RoboCopy /? and read the output.

– Compo
Jan 4 at 6:23













%search% is a file? If not, then add an extra after %search%.

– double-beep
Jan 4 at 14:39







%search% is a file? If not, then add an extra after %search%.

– double-beep
Jan 4 at 14:39















@Compo i wasnt able to use robocopy in this instance as i couldnt figure out how to initiate it in the DO and also reference the %%a. If possible i know robocopy would be better as i get a nice clean output. i was going to try xxcopy but it appears to have its limitations also

– David Zammit
Jan 6 at 23:08





@Compo i wasnt able to use robocopy in this instance as i couldnt figure out how to initiate it in the DO and also reference the %%a. If possible i know robocopy would be better as i get a nice clean output. i was going to try xxcopy but it appears to have its limitations also

– David Zammit
Jan 6 at 23:08













@double-beep %search% is referencing the users input for Criteria, this is any string really that could be within the files, example we have *.txt files and on the first line is a reference number AA-XXXXX, so if i type in that criteria it searches all the files that are related to it.

– David Zammit
Jan 6 at 23:13





@double-beep %search% is referencing the users input for Criteria, this is any string really that could be within the files, example we have *.txt files and on the first line is a reference number AA-XXXXX, so if i type in that criteria it searches all the files that are related to it.

– David Zammit
Jan 6 at 23:13












1 Answer
1






active

oldest

votes


















0














Just use forfiles /D dd/mm/yyyy to search files never than date or use minus sign in front of date to revert it to older than date. It also takes +30 type days as date.






share|improve this answer
























  • i was looking at forfiles but i could only see this as being useful if i somehow could narrow the file count for searching by nesting the findstr within a forfiles by date.

    – David Zammit
    Jan 6 at 23:15












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54033353%2fwindows-batch-script-for-finding-string-within-files-with-a-specified-date-and-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Just use forfiles /D dd/mm/yyyy to search files never than date or use minus sign in front of date to revert it to older than date. It also takes +30 type days as date.






share|improve this answer
























  • i was looking at forfiles but i could only see this as being useful if i somehow could narrow the file count for searching by nesting the findstr within a forfiles by date.

    – David Zammit
    Jan 6 at 23:15
















0














Just use forfiles /D dd/mm/yyyy to search files never than date or use minus sign in front of date to revert it to older than date. It also takes +30 type days as date.






share|improve this answer
























  • i was looking at forfiles but i could only see this as being useful if i somehow could narrow the file count for searching by nesting the findstr within a forfiles by date.

    – David Zammit
    Jan 6 at 23:15














0












0








0







Just use forfiles /D dd/mm/yyyy to search files never than date or use minus sign in front of date to revert it to older than date. It also takes +30 type days as date.






share|improve this answer













Just use forfiles /D dd/mm/yyyy to search files never than date or use minus sign in front of date to revert it to older than date. It also takes +30 type days as date.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 4 at 5:24









Stacking For HeapStacking For Heap

27429




27429













  • i was looking at forfiles but i could only see this as being useful if i somehow could narrow the file count for searching by nesting the findstr within a forfiles by date.

    – David Zammit
    Jan 6 at 23:15



















  • i was looking at forfiles but i could only see this as being useful if i somehow could narrow the file count for searching by nesting the findstr within a forfiles by date.

    – David Zammit
    Jan 6 at 23:15

















i was looking at forfiles but i could only see this as being useful if i somehow could narrow the file count for searching by nesting the findstr within a forfiles by date.

– David Zammit
Jan 6 at 23:15





i was looking at forfiles but i could only see this as being useful if i somehow could narrow the file count for searching by nesting the findstr within a forfiles by date.

– David Zammit
Jan 6 at 23:15




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54033353%2fwindows-batch-script-for-finding-string-within-files-with-a-specified-date-and-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas