View unanswered posts | View active topics It is currently 19 Oct 2014 22:20



Post new topic Reply to topic  [ 9 posts ] 
Copy files from subfolders to one folder based on criteria 
Author Message

Joined: 18 Oct 2010 14:51
Posts: 12
Post Copy files from subfolders to one folder based on criteria
I have a directory structure:

K:\Franchises\Seattle
K:\Franchises\New York
K:\Franchises\Boston...

and each city has hundreds of files. I need to copy all the files from each city's folder having Dominos in the filename to C:\MyLocalCopies\Dominos. Likewise all files having PizzaHut in the filename will go in C:\MyLocalCopies\PizzaHut. I have tried using a for loop with variable name but no luck so far. Would one of the smart people out there please help.

Thanks


20 Oct 2010 15:11
Profile
Expert

Joined: 04 Jun 2010 20:05
Posts: 177
Location: Russia
Post Re: Copy files from subfolders to one folder based on criter
Code:
for %%a in (Dominos PizzaHut) do (
for /f "delims=" %%b in ('dir /b/s/a-d "K:\Franchises\*%%a*"') do (
xcopy /q/y "%%b" "C:\MyLocalCopies\%%a\"
))


20 Oct 2010 20:51
Profile

Joined: 18 Oct 2010 14:51
Posts: 12
Post Re: Copy files from subfolders to one folder based on criter
Works perfectly. Thank you


21 Oct 2010 08:13
Profile

Joined: 18 Oct 2010 14:51
Posts: 12
Post Re: Copy files from subfolders to one folder based on criter
Is there a way to delete columns N onwards in all folders in C:\MyLocalCopies\ such as C:\MyLocalCopies\PizzaHut, C:\MyLocalCopies\Unos etc. except C:\MyLocalCopies\Dominos from which I need columns M onwards deleted?

Thank you


21 Oct 2010 10:22
Profile

Joined: 18 Oct 2010 14:51
Posts: 12
Post Re: Copy files from subfolders to one folder based on criter
Forgot to mention...All the files in all subfolders of C:\MyLocalCopies\ are Excel files


21 Oct 2010 10:25
Profile
Expert

Joined: 22 Jan 2010 18:01
Posts: 1800
Location: Germany
Post Re: Copy files from subfolders to one folder based on criter
Don't get it. You want to delete columns in excel files using batch?

Regards
aGerman


21 Oct 2010 16:33
Profile

Joined: 18 Oct 2010 14:51
Posts: 12
Post Re: Copy files from subfolders to one folder based on criter
Yes


21 Oct 2010 18:14
Profile
Expert

Joined: 04 Jun 2010 20:05
Posts: 177
Location: Russia
Post Re: Copy files from subfolders to one folder based on criter
well... on MSOffice 2003 XLS files tested...
for example, N=3, M=2 (parm of StdInXlsDelCol() func)
Code:
@set @x=0 /*
@dir /b/s/a-d "C:\MyLocalCopies\*.xls"|findstr /vbc:"C:\MyLocalCopies\Dominos"|cscript //nologo /e:jscript "%~0" "StdInXlsDelCol(3)"
@dir /b/s/a-d "C:\MyLocalCopies\Dominos\*.xls"|cscript //nologo /e:jscript "%~0" "StdInXlsDelCol(2)"
@exit */
eval(WScript.Arguments.Item(0));

function StdInXlsDelCol(col) {
  var str,xls = WScript.CreateObject("Excel.Application");
  var fso = WScript.CreateObject("Scripting.FileSystemObject");
  while (!WScript.StdIn.AtEndOfStream) {
    str = WScript.StdIn.ReadLine();
    WScript.Echo(str);
    if (fso.FileExists(str)) {
      xls.WorkBooks.Open(fso.GetAbsolutePathName(str));
      xls.Application.DisplayAlerts = 0;
      xls.Application.ScreenUpdating = 0;
      xls.ActiveWorkbook.Sheets(1).Columns(parseInt(col)).Delete;
      xls.ActiveWorkBook.Save;
      xls.ActiveWorkBook.Close;
      xls.Close;
}}}


22 Oct 2010 02:14
Profile

Joined: 11 Oct 2011 06:29
Posts: 1
Post Re: Copy files from subfolders to one folder based on criter
Hey guys, am trying to copy a file from one sub-subfolder to another in the command prompt. Am talking....d:\Applications\backup\supersoftware\DATA\300.xls to c:\programfiles\Royzone\Playmaker\play. Please help.
Thanks a million.


11 Oct 2011 07:07
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.