문제 설명
Excel VBA ‑ WinSCP 명령줄에 공백이 있는 변수 경로 전달 (Excel VBA ‑ Passing a variable path with spaces to WinSCP command‑line)
내 Excel 책(vba 코드를 처음으로 작성함) 중 하나에 이 게시물 하단에 코드가 있습니다. 여기의 목표는 사용자가 다음을 수행할 수 있도록 하는 것입니다.
- 임시 파일 이름으로 MXLight 소프트웨어를 사용하여 비디오 인코딩 시작
- 현재 비디오에 있는 사람이 있는 셀 선택
- 비디오 인코딩을 중지하고, 임시 파일의 이름을 변경하고, 특정 폴더로 이동하고, WinSCP 소프트웨어를 통해 FTP를 통해 업로드하고, 녹색으로 표시하고, 한 셀 아래로 이동합니다.
그래서 이벤트 기간 동안:
- Sub StartMXL인 버튼 1을 누르세요.
- 셀을 강조 표시합니다.
- Sub StartMXL인 버튼 2를 누릅니다. StopAndProcess
제 질문은 다음과 같습니다.
1) 무엇보다도, 전체(중지 및 처리) 버튼은 업로드 기능이 실패하여 작동하지 않습니다. 왜냐하면 어떻게 winscp 명령이 참조된 변수를 사용하고 그 단어를 사용하려고 하지 않는지 알 수 없기 때문입니다. Sub Upload 아래에 있는 코드를 확인하고 시도했을 때의 로그 파일은 다음과 같습니다.
1 . 2015‑11‑12 17:53:18.490 Connected
2 . 2015‑11‑12 17:53:18.490 Using FTP protocol.
3 . 2015‑11‑12 17:53:18.490 Doing startup conversation with host.
4 > 2015‑11‑12 17:53:18.491 PWD
5 < 2015‑11‑12 17:53:18.520 257 "/" is the current directory
6 . 2015‑11‑12 17:53:18.520 Getting current directory name.
7 . 2015‑11‑12 17:53:18.520 Startup conversation with host finished.
8 < 2015‑11‑12 17:53:18.520 Script: Active session: [1] ftp1934501@ftp.kaltura.com
9 > 2015‑11‑12 17:53:18.520 Script: put RealFile
10. 2015‑11‑12 17:53:18.520 Copying 1 files/directories to remote directory "/"
11. 2015‑11‑12 17:53:18.520 PrTime: Yes; PrRO: No; Rght: rw‑r‑‑r‑‑; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask:
12. 2015‑11‑12 17:53:18.520 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
13. 2015‑11‑12 17:53:18.520 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
14* 2015‑11‑12 17:53:18.520 (EOSError) System Error. Code: 2.
15* 2015‑11‑12 17:53:18.520 The system cannot find the file specified
9번째 줄에서 파일 이름과 폴더 구조가 있는 변수의 내용을 사용하는 대신 "RealFile"이라는 파일을 문자 그대로 업로드하려고 하는 것을 볼 수 있습니다. 그 변수는 이름을 변경하고 이동할 때와 같이 코드의 다른 부분에서 작동합니다.
어떤 아이디어가 있습니까?
전체에 대한 전체 코드는 다음과 같습니다.
Public Sub StartMXL()
Dim MXLapp As String
MXLapp = "C:\1a7j42w\MXLight‑2‑4‑0\MXLight.exe"
Shell (MXLapp & " record=on"), vbNormalNoFocus
AppActivate Application.Caption
End Sub
‑‑‑
Public Sub StopMXL()
Dim MXLapp As String
MXLapp = "C:\1a7j42w\MXLight‑2‑4‑0\MXLight.exe"
Shell (MXLapp & " record=off"), vbNormalNoFocus
AppActivate Application.Caption
End Sub
‑‑‑
Sub ChooseRootDir()
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please choose a folder"
.AllowMultiSelect = False
If .Show = ‑1 Then Sheets("rawdata").Range("I1").Value = .SelectedItems(1)
End With
End Sub
‑‑‑
Public Sub RenameAndMove()
Dim TempFile As String
Dim RealFile As String
If Len(Dir(Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value, vbDirectory)) = 0 Then
MkDir Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value
End If
If Len(Dir(Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value, vbDirectory)) = 0 Then
MkDir Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value
End If
If Len(Dir(Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value, vbDirectory)) = 0 Then
MkDir Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value
End If
TempFile = Sheets("rawdata").Range("I1").Value & "\tempfile\spiderman.TS"
RealFile = Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value & "\" & ActiveCell.Value & ".TS"
Name TempFile As RealFile
End Sub
‑‑‑
Public Sub Upload()
Dim RealFile As String
Dim TempFile As String
RealFile = Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value & "\" & ActiveCell.Value & ".TS"
TempFile = "C:\1a7j42w\MXLight‑2‑4‑0\recordings\tempfile\spiderman.TS"
Call Shell( _
"C:\1a7j42w\WinSCP\WinSCP.com /log=C:\1a7j42w\WinSCP\excel.log /command " & _
"""open ftp://ftp1934501:da7Mc4Fr@ftp.kaltura.com/"" " & _
"""put RealFile"" " & _
"""exit""")
End Sub
‑‑‑
Sub StopAndProcess()
Call StopMXL
Call RenameAndMove
Call Upload
Selection.Interior.ColorIndex = 4
ActiveCell.Offset(1, 0).Select
End Sub
## 참조 솔루션 #### 방법 1:
In WinSCP script, you want:
put "path with space"
See Command parameters with spaces.
On WinSCP command line, you have to enclose each command to a double quotes and double all double quotes in the command itself:
"put ""path with space"""
See WinSCP command‑line syntax.
In VB you need to enclose the string in double quotes and double all double quotes in the string itself:
"""put """"path with space"""""" "
And to replace the path with a variable, substitute the path with space
with " & RealFile & "
.
This gives you:
"""put """"" & RealFile & """"""" "
(by Jarmer、Martin Prikryl)