Page 1 of 1

Display commands only if file exists

Posted: 11 Nov 2018 14:47
by activoice
So I have this batch files that looks at the filenames for various videos that I download and moves them from a common folder to a destination folder. It runs fine, but it looks messy in the command window as it displays a line for every file that it checks to see if it exists.. I would like to only display the commands in the window for files that actually exist, and not see all of the ones that no file existed for...

For example my batch file currently looks like this
movefiles.cmd
if exist "\\192.168.1.85\downloads\complete\Television\abc*.*" move "\\192.168.1.85\downloads\complete\Television\abc*.*" "\\192.168.1.85\videos2\abc"
if exist "\\192.168.1.85\downloads\complete\Television\def*.*" move "\\192.168.1.85\downloads\complete\Television\def*.*" "\\192.168.1.85\videos1\def\"
if exist "\\192.168.1.85\downloads\complete\Television\ghi*.*" move "\\192.168.1.85\downloads\complete\Television\ghi*.*" "\\192.168.1.85\videos2\ghi\"

But if I run this and only the file def.mkv exists I still see all 3 commands in the command window
if exist "\\192.168.1.85\downloads\complete\Television\abc*.*" move "\\192.168.1.85\downloads\complete\Television\abc*.*" "\\192.168.1.85\videos2\abc"
if exist "\\192.168.1.85\downloads\complete\Television\def*.*" move "\\192.168.1.85\downloads\complete\Television\def*.*" "\\192.168.1.85\videos1\def\"
if exist "\\192.168.1.85\downloads\complete\Television\ghi*.*" move "\\192.168.1.85\downloads\complete\Television\ghi*.*" "\\192.168.1.85\videos2\ghi\"

Instead I would like to only see the one line for the file that does actually exist and that it's moving
if exist "\\192.168.1.85\downloads\complete\Television\def*.*" move "\\192.168.1.85\downloads\complete\Television\def*.*" "\\192.168.1.85\videos1\def\"


Is there a way to do that? Perhaps with the Echo command?

Re: Display commands only if file exists

Posted: 11 Nov 2018 19:41
by Squashman
At the top of your script use the ECHO command to turn off verbose output of other command.

Code: Select all

@echo off

Re: Display commands only if file exists

Posted: 12 Nov 2018 08:31
by activoice
Wow thanks, didn't realize it was that simple