ZayaMia wrote:ok, I think this is getting out of hand since I didn't made my point clearly I think.
You made it clear enough i think, and the batch
"mybatAnd.bat" (above) is exactly doing what you have asked for;
although you haven't given the right search phrases.
I suspect you just don't belive me (whyever)?!
You have made the work to explain in detail, so i will do the same in case something might be unclear.
ZayaMia wrote:Moreover I just need those from todays date. XML files from yesterday or so aren't in my interest.
This is done by the line:
Code: Select all
forfiles /P "." /M "*.xml" /D +%date% /C "cmd /c for %%a in (@file) do @(echo(%%~a") | >"fileList.txt" findstr /V "^$"
The above forfiles command searches all xml files ("*.xml") in the actual directory "." (= "\\server5\Datapool", because you have changed to it using pushd), and if the files have the date of today ("%date%) or later then it prints the filename to stdout, which is redirected to a pipe, to be filtered by findstr to delete the trailing empty line (created by findstr).
The filelist then is redirected to the file "fileList.txt".
(One error reason could be, that you might have insufficient rights to write onto the server as mentioned above together with the solution.)
Files from yesterday shouldn't be listed, except if the date on your pc is just wrong, or if you have replaced the "%date%" part with something else which results in for example yesterdays date.
ZayaMia wrote:So if the Name "PHIL" and currentState "Executive13" match, which are always both on the same line ,
This is done by the line:
Code: Select all
>"result.txt" findstr /r /i /m /f:"fileList.txt" /C:"Cale.*Toyota231" /C:"Toyota231.*Cale"
Note that it searches for "Cale" and "Toyota231" instead of "PHIL" and "Executive13", because you have said so.
Just replace any "Cale" with "PHIL", and "Toyota231" with "Executive13", and it should search what you really are looking for.
The names of all files containing the given search pattern are stored to the file "result.txt".
ZayaMia wrote:they should be moved from \\server5\Datapool to C:\Users\folder1.
This is done by the line:
Code: Select all
for /f "usebackq tokens=* delims=" %%a in ("result.txt") do copy "%%~a" "C:\Users\folder1"
The "for/f" command loops over each line in the file "result.txt" (= list of matching files) and copy the files to "C:\Users\folder1".
Note that your local directory should be "\\server5\Datapool" (pushd), so you are copying the matching files from "\\server5\Datapool" to "C:\Users\folder1".
ZayaMia wrote:XML file names aren't named by Cale or Toyota231.
These is only contained in a batch file, that proves, that the algorithm works and is just some "test data":
I've done this because i don't know the names of the files on your server, and the algorithm needs some files to test.
But they are not hardcoded and found because of its content (and not its name):
You could arbitrarily rename them as you wish, and the batch will still find them.
Prove for that ("testAnd2.bat", with the real search patterns):
Code: Select all
@echo off
>"Any.xml" echo(PHIL
>"Name.xml" echo(Executive13
>"You.xml" echo(Executive13PHIL
>"wish.xml" echo(PHILExecutive13
setlocal enableExtensions disableDelayedExpansion
rem pushd \\server5\Datapool
forfiles /P "." /M "*.xml" /D +%date% /C "cmd /c for %%a in (@file) do @(echo(%%~a") | >"fileList.txt" findstr /V "^$"
>"result.txt" findstr /r /i /m /f:"fileList.txt" /C:"PHIL.*Executive13" /C:"Executive13.*PHIL"
for /f "usebackq tokens=* delims=" %%a in ("result.txt") do echo copy "%%~a" "C:\Users\folder1"
rem del "fileList.txt"
rem del "result.txt"
goto :eof
Note that the files with "test" in it are in this case just test files.
The file named "myBatAnd.bat" (or similar) contain the real algorithm.
Result:
Code: Select all
Z:\>testAnd2.bat
copy "wish.xml" "C:\Users\folder1"
copy "You.xml" "C:\Users\folder1"
Z:\>
ZayaMia wrote:So my attempt here was to search for a faster solution to move ALL specified files from todays date into another folder.
I hope its clear now.
Again, you should note that the above
"mybatAnd.bat" (above) is doing the exact same thing, which i beside this have proven to you.
If the batch is doing something other than this on your system, you have to provide more information, as i said above:
If you changed something in the code, you should also mention it (for example if you have changed "%date%" with something else).
penpen