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;
}
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
add a comment |
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
Open a Command Prompt window, enterRoboCopy /?
and read the output.
– Compo
Jan 4 at 6:23
%search%
is a file? If not, then add an extra%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
add a comment |
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
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
batch-file
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, enterRoboCopy /?
and read the output.
– Compo
Jan 4 at 6:23
%search%
is a file? If not, then add an extra%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
add a comment |
Open a Command Prompt window, enterRoboCopy /?
and read the output.
– Compo
Jan 4 at 6:23
%search%
is a file? If not, then add an extra%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
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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%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