Display commands only if file exists

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
activoice
Posts: 2
Joined: 11 Nov 2018 14:30

Display commands only if file exists

#1 Post by activoice » 11 Nov 2018 14:47

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?

Squashman
Expert
Posts: 4012
Joined: 23 Dec 2011 13:59

Re: Display commands only if file exists

#2 Post by Squashman » 11 Nov 2018 19:41

At the top of your script use the ECHO command to turn off verbose output of other command.

Code: Select all

@echo off

activoice
Posts: 2
Joined: 11 Nov 2018 14:30

Re: Display commands only if file exists

#3 Post by activoice » 12 Nov 2018 08:31

Wow thanks, didn't realize it was that simple

Post Reply