Copy files from subfolders to one folder based on criteria

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DOSScriptWriter
Posts: 12
Joined: 18 Oct 2010 14:51

Copy files from subfolders to one folder based on criteria

#1 Post by DOSScriptWriter » 20 Oct 2010 15:11

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

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

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

#2 Post by amel27 » 20 Oct 2010 20:51

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

DOSScriptWriter
Posts: 12
Joined: 18 Oct 2010 14:51

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

#3 Post by DOSScriptWriter » 21 Oct 2010 08:13

Works perfectly. Thank you

DOSScriptWriter
Posts: 12
Joined: 18 Oct 2010 14:51

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

#4 Post by DOSScriptWriter » 21 Oct 2010 10:22

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

DOSScriptWriter
Posts: 12
Joined: 18 Oct 2010 14:51

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

#5 Post by DOSScriptWriter » 21 Oct 2010 10:25

Forgot to mention...All the files in all subfolders of C:\MyLocalCopies\ are Excel files

aGerman
Expert
Posts: 3063
Joined: 22 Jan 2010 18:01
Location: Germany

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

#6 Post by aGerman » 21 Oct 2010 16:33

Don't get it. You want to delete columns in excel files using batch?

Regards
aGerman


amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

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

#8 Post by amel27 » 22 Oct 2010 02:14

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

Koolkally
Posts: 1
Joined: 11 Oct 2011 06:29

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

#9 Post by Koolkally » 11 Oct 2011 07:07

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.

Post Reply