Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Powershell & Windows batch: move log files and it equivalent based on contain

Hello experts,

I would like to cover an additional need related to question https://www.experts-exchange.com/questions/29153505/Powershell-Windows-Batch-Vbscript-move-files-based-on-contain.html
Solution proposed move log files from input to output if one file contains at least one line which doesn't start with 0.

Powershell approach:

$sourceFolder = 'C:\Temp\input'
$targetFolder = 'C:\Temp\output'
Get-ChildItem -Path $sourceFolder -Filter *.log |
	Select-String -Pattern '^[^0]' -List |
	ForEach-Object {Move-Item -Path $_.Path -Destination $targetFolder}

Open in new window


Batch approach:
for /f "tokens=*" %%A in ('findstr /m /b /v /c:"0;" "C:\TEMP\BASEDIR\*.log"') do move "%%A" "C:\TEMP\DESTDIR"

Open in new window


Additional need:

In input folder I have .log file and also it .csv file equivalent example : ReqXXXX.log and ReqXXXX.csv,

I would like:
-move log file in output (as is)  
-move csv file equivalent into an output2 folder

Assumption:
-Every log file has it csv equivalent.

If you have questions, please contact me.
Thank you for your help.
EXPERT CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luis Diaz

ASKER

Tested and it works.
Thank you very much for your help!