2013-02-13 3 views
1

다음 VBS 파일을 함께 묶어 Excel 원본 파일을 읽고 Excel 열 A를 기반으로하는 이름과 B 열 (연결됨)을 기반으로하는 내용으로 파일을 만들었습니다. 이 모든 작품 ...VBScript : Excel에서 폴더 구조가있는 파일 만들기

Dim xlsFile 
Dim objExcel 
Dim outFile 
Dim path 

path = "C:\Documents and Settings\Andy\Desktop\SHORTURLs\JSPs" 
xlsFile = path & "\urls.xls" 
Set objExcel = WScript.CreateObject("Excel.Application") 
objExcel.Workbooks.open(xlsFile) 
' Create the File System Object 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

intRow = 2 'Row 1 contains headings 

' Here is the loop that cycles through the cells 
Do Until objExcel.Cells(intRow,1).Value = "" 
    strFile = objExcel.Cells(intRow, 1).Value 
    strDestURL = objExcel.Cells(intRow, 2).Value 

    ' -- The heart of the create file script 
    'Set objTextFile = objFSO.CreateTextFile("./" & strFile & ".jsp", True) 
    outFile = path & "" & strFile & ".jsp" 
    Set objTextFile = objFSO.CreateTextFile(outFile, True) 

    ' Prep file contents 
    sText = "<%" & vbCrLf 
    sText = sText & "//REDIRECT301" & vbCrLf 
    sText = sText & "//System.out.println(""<LOGGED> "" + " & strDestURL & ");" & vbCrLf 
    sText = sText & "String dest = """ & strDestURL & """;" & vbCrLf 
    sText = sText & "response.setStatus(response.SC_MOVED_PERMANENTLY); // response.SC_MOVED_TEMPORARILY [OR] response.SC_MOVED_PERMANENTLY" & vbCrLf 
    sText = sText & "response.setHeader(""Location"", dest);" & vbCrLf 
    sText = sText & "response.setHeader(""Connection"", ""close"");" & vbCrLf 
    sText = sText & "%>" 
    ' Write a line. 
    objTextFile.Write(sText) 

    objTextFile.Close 
    intRow = intRow + 1 
Loop 

objExcel.Quit 
WScript.Quit 

그러나, 지금 (열 B는 영향을받지 않습니다) A 열을 기반으로 폴더 구조로 파일을 생성하기 위해 VBS를 수정해야합니다. 엑셀 스키마 :

+----------------------+----------------------+ 
|  Column A  |  Column B  | 
+----------------------+----------------------+ 
| /folder/filename.jsp | /url/destination.jsp | 
+----------------------+----------------------+ 
| /folder/filename.jsp | /url/destination.jsp | 
+----------------------+----------------------+ 
| /folder/filename.jsp | /url/destination.jsp | 
+----------------------+----------------------+ 

내가 그 폴더 안에 폴더와 파일을 만드는 방법에 대해 어떻게 갈 것인가? FYI : 폴더 구조가 1 깊이 이상이어야합니다 (즉, /folder/file.xxx이 아닌 /folder/folder/file.xxx).

추신. JSP 파일의 response.setHeader()은 나쁜 습관이지만 슬프게도 우리는 이런 식으로해야한다는 것을 알고 있습니다.

답변

4

FSO를 사용하십시오.

  1. .GetParentFolderName()

  2. .FolderExists() 당신이 디렉토리
  3. .CreateFolder() 경우를 만들 필요가 있는지 여부를 확인하는 일반적인 경로 접두사를 앞에 추가 할 파일 스펙
  4. .BuildPath()에서 디렉토리를 얻기 위해 필요한
관련 문제