I must be doing something wrong with my code, but I am having trouble figuring it out.
What I'm trying to do is to create a .bat file to re-organize some files from one folder into many folders, according to an index file that is in Excel.
Here's the data pasted directly from Excel...
Financials
2007 Documents
2007 Acme, Inc. Tax Returns.PDF
2007 Tax Workpapers.pdf
2007 Acme, Inc. Tax Returns.PDF
2007 Quarterly payroll data - Corporate.pdf
2007 Tax Workpapers.pdf
2007 Acme, Inc. Tax Returns.PDF
2007 Quarterly payroll data - Corporate.pdf
2007 Quarterly payroll data - Corporate.pdf
2007 Tax Workpapers.pdf
2008 Quarterly payroll data - Corporate.pdf
@Value Service Agreement.pdf
Aged AP 12.31.07 Acme Corp.xls
Aged AR 12.31.07 Acme Corp.xls
Amended and Restated Acme Capital Markets License final.DOC
Corp Additional payroll procedures .xls
Corporate Other Rec & Assets.pdf
Corporate Revenue.pdf
Corporate Tax Due Diligence Checklist.xls
Corporate wages by state.xls
Corporate_20_Ownership Changes.doc
Employee Documents
101 2008 Headquarters EBITDA Format.xls
101 Headquarters - payroll reports.pdf
101 Headquarters - Tax Due Diligence Checklist.xls
101 Headquarters Change in Ownership.doc
2001 Bank Reconciliations & Bank Stmts.pdf
2002 Money Market Acct.pdf
2007 Headquarters EBITDA and TB.xls
2601 Prepaid insurance.xls
3201 gaap depreciation report.xls
3801 Operating Agreement.pdf
3802 Other Assets.pdf
Untagged
Local CPAs Contact List.xls
Request #17 Car Loan.pdf
Here's the output I'm getting right now, with the errors...
mkdir folders
cd folders
mkdir "Financials"
mkdir "Financials"\"2007 Documents"
copy files\"2007 Acme, Inc. Tax Returns.PDF" folders\"Financials"\"2007 Documents"
copy files\"DDE_SERVICE_INVALID" folders\"Financials"\"2007 Documents"
copy files\"DDE_SERVICE_INVALID" folders\"Financials"\"2007 Documents"
copy files\"DDE_SERVICE_INVALID" folders\"Financials"\"2007 Documents"
copy files\"DDE_SERVICE_INVALID" folders\"Financials"\"2007 Documents"
copy files\"DDE_SERVICE_INVALID" folders\"Financials"\"2007 Documents"
copy files\"DDE_SERVICE_INVALID" folders\"Financials"\"2007 Documents"
Here's my code...
Code: Select all
//Specify the path of the Excel file here
Let>filename=C:\Folderizer\Input file.xls
IfFileExists>filename
//Start Excel
ExecuteFile>filename
WaitWindowOpen>Microsoft Excel -*
//Ask how many rows we should get
Input>maxrows,How many rows shall I process?,10
//As an example I'm going to paste the data into Notepad
Run>Notepad.exe
WaitWindowOpen>Untitled - Notepad
Send>mkdir folders%CR%
Send>cd folders%CR%
Let>r=1
Repeat>r
//get the fields for this row
DDERequest>Excel,filename,R%r%C1,field_1,60
If>field_1=DDE_SERVICE_INVALID
Let>field_1=%topleveltag%
DDERequest>Excel,filename,R%r%C3,field_3,60
Goto>fileonlyrow
EndIf
DDERequest>Excel,filename,R%r%C2,field_2,60
DDERequest>Excel,filename,R%r%C3,field_3,60
//remove the CRLF that Excel adds
StringReplace>field_1,CRLF,,field_1
StringReplace>field_2,CRLF,,field_2
StringReplace>field_3,CRLF,,field_3
//Get the length of each field, so I know how to treat it
Length>%field_1%,len1
Length>%field_2%,len2
Length>%field_3%,len3
//Trim each field
VBSTART
VBEND
VBEval>LTrim("%field_1%"),field_1
VBEval>LTrim("%field_2%"),field_2
VBEval>LTrim("%field_3%"),field_3
//For this example we'll just paste each row into Notepad
SetFocus>Notepad*
If>len1>0
Let>topleveltag=%field_1%
Send>mkdir "%field_1%"
Goto>nextrecord
EndIf
If>len2>0
Let>secondleveltag=%field_2%
Send>mkdir "%topleveltag%"\"%secondleveltag%"
Goto>nextrecord
EndIf
If>len3>0
Label>fileonlyrow
Let>filename=%field_3%
Send>copy files\"%filename%" folders\"%topleveltag%"\"%secondleveltag%"
Goto>nextrecord
EndIf
Label>nextrecord
'Press Enter
Send>%CR%
Let>r=r+1
Wait>0.05
Until>r=maxrows
Else
MessageModal>Could not find: %filename%
Endif