Page 1 of 1

Copy files from subfolders to one folder based on criteria

Posted: 20 Oct 2010 15:11
by DOSScriptWriter
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

Re: Copy files from subfolders to one folder based on criter

Posted: 20 Oct 2010 20:51
by amel27

Code: Select all

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\"
))

Re: Copy files from subfolders to one folder based on criter

Posted: 21 Oct 2010 08:13
by DOSScriptWriter
Works perfectly. Thank you

Re: Copy files from subfolders to one folder based on criter

Posted: 21 Oct 2010 10:22
by DOSScriptWriter
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

Re: Copy files from subfolders to one folder based on criter

Posted: 21 Oct 2010 10:25
by DOSScriptWriter
Forgot to mention...All the files in all subfolders of C:\MyLocalCopies\ are Excel files

Re: Copy files from subfolders to one folder based on criter

Posted: 21 Oct 2010 16:33
by aGerman
Don't get it. You want to delete columns in excel files using batch?

Regards
aGerman

Re: Copy files from subfolders to one folder based on criter

Posted: 21 Oct 2010 18:14
by DOSScriptWriter
Yes

Re: Copy files from subfolders to one folder based on criter

Posted: 22 Oct 2010 02:14
by amel27
well... on MSOffice 2003 XLS files tested...
for example, N=3, M=2 (parm of StdInXlsDelCol() func)

Code: Select all

@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;
}}}

Re: Copy files from subfolders to one folder based on criter

Posted: 11 Oct 2011 07:07
by Koolkally
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.