copy specific files from one folder 2 another

Microsoft Windows 7 professional 64-bit
July 30, 2010 at 13:36:56
Specs: Windows XP or Windows 7
Hello,

I have 20 files in one folder. I need to copy only those files containing the word "fact" (In sql command : like "%fact%") in the filename to another folder. Can anyone suggest a batch file which serves this purpose?

Thanks,
Manoj


See More: copy specific files from one folder 2 another

Report •

#1
August 1, 2010 at 10:09:55
This should work, sorry for the wait.

Here it is:

@ECHO OFF
SETLOCAL EnableDelayedExpansion

FOR /f "tokens=*" %%a IN ('FINDSTR /i /m "fact" "Location:\of\files\*.txt"') DO (
	IF "!ERRORLEVEL!"=="0" MOVE %%a "Loaction:\of\folder"
)

Hope I've helped!

EDIT: Added quotes to code to allow for spaces in the paths


Report •

#2
August 2, 2010 at 06:52:56
Hello Matt,

Thanks for the code. But i seem to be not getting the result.
Please let me know if what am trying is correct.

Source folder: C:\SourceTest
Destination folder: C:\DestinationTest

In source folder i have a csv file which contains the word "fact".

Now here is how i modified the code,

@ECHO OFF
SETLOCAL EnableDelayedExpansion

FOR /f "tokens=*" %%a IN ('FINDSTR /i /m "fact" "c:\SourceTest\*.csv"') DO (
IF "!ERRORLEVEL!"=="0" MOVE %%a "c:\DestinationTest"
)


But it doesnot seem to work.. Can you help me out on this as i am new to batch scripting??


Report •

#3
August 2, 2010 at 08:15:13
Also the search is to find the filename containing words "fact" and "current"(eg filename "Top 10 Prov IN Fact Jumbo Current Rank.CSV"). Please help me out..

Report •

Related Solutions

#4
August 2, 2010 at 08:36:46
The script I wrote was to move files containing the word fact WITHIN the file not in the title.
I'll see if I can do figure something out. Give me a little bit of time, as I'm not an expert at these sort of things. I'm also defragging my hard drive at the moment so I'm a little bogged down hehe.

Report •

#5
August 2, 2010 at 08:40:57
Ok.. Lemme know if you could find a solution for this..

Report •

#6
August 2, 2010 at 08:53:54
Alright sorry about the misunderstanding.

This should work for you:

@ECHO OFF
SETLOCAL EnableDelayedExpansion

FOR %%a IN (Fact) DO (
	MOVE "C:\SourceTest\*%%a*.CSV" "C:\DestinationTest"
)
PAUSE

You will need to have the batch file in the same location as the CSV files you want to move though.

EDIT: Never mind, had a little brain fart there, fixed it and should now work where ever the batch file is.

Good Luck!


Report •

#7
August 2, 2010 at 09:24:23
That worked perfect.. Thanks a ton Matt

Report •

#8
August 2, 2010 at 09:30:02
No problem! Just glad I was able to help.

Report •

#9
October 19, 2010 at 05:47:31
hi matt
I need u'r help to move selected folders from one location to another
i have create a csv file having all folder name i want to move .if I want use same script what do i need to chane

Report •

#10
October 19, 2010 at 15:11:10
Since this is quite an old thread, next time I recommend you make a new one.

However:

@ECHO OFF
SETLOCAL EnableDelayedExpansion

FOR /f %%a IN (MyFile.csv) DO (
	MOVE "P:\a\t\h\%%a" "P:\a\t\h\%%a"
)

Can I put a question here?


Report •

#11
October 20, 2010 at 02:30:14
its worked .thanks lot matt .

Report •

Ask Question