2014-09-15 2 views
0

복사 할 위치를 선택하기 위해 폴더 선택기 대화 상자를 여는 부분이있는 배치 파일이 있습니다. 처음에는 문제가 내가 데스크톱에 코드를 작성한 것으로 생각하고 서버의 최종 위치로 옮겼습니다. 하지만 지금은 그것이 작동 여부를 결정할 때 완전히 무작위로 보인다는 것을 발견했습니다. 일부 폴더는 괜찮습니다. 그렇지 않습니다. 꽤 혼란스러워!배치 코드 - 폴더 대화 상자 - 코드 가끔 ​​작동 함

유일한 오류는 현재 예기치 않은 설정입니다. 내가 txt 파일로 출력 코드를 @echo 제거하고 경우에도, 그것은 코드의 내부 문자열의 무리를 통해 루핑 및 % 변수 thumbdrivefolder 내 %로 저장되는 것 같다 ...

@echo off 

for %%I in (powershell.exe) do if "%%~$PATH:I" neq "" (
    set chooser=powershell -sta "Add-Type -AssemblyName System.windows.forms|Out-Null;$f=New-Object System.Windows.Forms.FolderBrowserDialog;$f.SelectedPath='%cd%';$f.Description='About to make a copy of the job folder: %jobfolder% (for transport). Please select a folder on an external/removable drive.';$f.ShowNewFolderButton=$true;$f.ShowDialog();$f.SelectedPath" 
) else (
    set chooser=%temp%\fchooser.exe 
    if exist !chooser! del !chooser! 
    >"%temp%\c.cs" echo using System;using System.Windows.Forms; 
    >>"%temp%\c.cs" echo class dummy{[STAThread] 
    >>"%temp%\c.cs" echo public static void Main^(^){ 
    >>"%temp%\c.cs" echo FolderBrowserDialog f=new FolderBrowserDialog^(^); 
    >>"%temp%\c.cs" echo f.SelectedPath=System.Environment.CurrentDirectory; 
    >>"%temp%\c.cs" echo f.Description="Please choose a folder."; 
    >>"%temp%\c.cs" echo f.ShowNewFolderButton=true; 
    >>"%temp%\c.cs" echo if^(f.ShowDialog^(^)==DialogResult.OK^){Console.Write^(f.SelectedPath^);}}} 
    for /f "delims=" %%I in ('dir /b /s "%windir%\microsoft.net\*csc.exe"') do (
     if not exist "!chooser!" "%%I" /nologo /out:"!chooser!" "%temp%\c.cs" 2>NUL 
    ) 
    del "%temp%\c.cs" 
    if not exist "!chooser!" (
     echo Error: Please install .NET 2.0 or newer, or install PowerShell. 
     goto :ERROR 
    ) 
) 
for /f "delims=" %%I in ('%chooser%') do set "thumbdrivefolder=%%I" 
IF NOT %thumbdrivefolder:~-1%==\ SET thumbdrivefolder=%thumbdrivefolder%\ 
del "%temp%\fchooser.exe" 2>NUL 

msg * %thumbdrivefolder% 
+0

을, 더 많은 테스트를 실행, 나는 그것이 대부분의 일을 발견 : if 문이 공간에 확실히 취약은 다음 시도 폴더는 작업 폴더에 넣을 때 예상됩니다. 이 폴더들은 경로가 있습니다 : "K : \ drafting \ jobs \ 1DETAILING \ FLOORTECH JULY'14-ON"---- 내가 시도한 다른 모든 경로가 공백과 아포스트로피를 가지고 있기 때문에 경로명이 엉망이 될 수 있습니까? . – user3709812

+0

이제 경로에 아포스트로피가 포함되어 있는지 확인해보십시오. '- 위의 코드를 편집 할 수있는 위치가 누구인지 아는 사람이 누구나 아포스트로피가있는 경로를 허용 할 수 있습니까? – user3709812

+0

공백은 배치 파일에서 처리해야합니다. 아포스트로피는 포이즌 문자가 아닙니다. – foxidrive

답변

0

set "chooser=%temp%\fchooser.exe" 
if exist "!chooser!" del "!chooser!" 

실제로

IF NOT "%thumbdrivefolder:~-1%"=="\" SET "thumbdrivefolder=%thumbdrivefolder%\" 
del "%temp%\fchooser.exe" 2>NUL 

msg * "%thumbdrivefolder%"