Batch script to search for variable/move files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
boostudiosgd
Posts: 1
Joined: 12 Dec 2012 11:51

Batch script to search for variable/move files

#1 Post by boostudiosgd » 12 Dec 2012 12:03

So iv'e had no luck trying to figure this out. Im trying to make a batch script to search for variable in file names (ex. HDTV) in one folder if file name contain the word then move to specific location on different hard drive.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch script to search for variable/move files

#2 Post by foxidrive » 12 Dec 2012 12:28

boostudiosgd wrote:So iv'e had no luck trying to figure this out. Im trying to make a batch script to search for variable in file names (ex. HDTV) in one folder if file name contain the word then move to specific location on different hard drive.


This searches all files in the current folder for HDTV (case sensitive) and moves those files to another drive.
Makes sure that the target folder exists first.


Code: Select all

@echo off
for /f "delims=:" %%a in ( ' findstr "HDTV" *.* ' ) do move "%%a" "d:\location\ on another drive\"

DigitalSnow
Posts: 20
Joined: 21 Dec 2012 13:36
Location: United States

Re: Batch script to search for variable/move files

#3 Post by DigitalSnow » 26 Dec 2012 19:38

If you are using Vista+ or Resource Pack on XP, use RoboCopy, else use xcopy and del.

Code: Select all

RoboCopy . "D:\Location\on another drive\" *HDTV* /MOV

See RoboCopy /? for help.

Code: Select all

xcopy *HDTV* "D:\Location\on another drive\" /I /Y
del *HDTV* /Q

See xcopy /? for help.

To use a batch variable replace the HDTV term with the variable's value.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch script to search for variable/move files

#4 Post by foxidrive » 26 Dec 2012 20:38

My mistake. I thought the task was to move files that *contain* HDTV.

Post Reply