2015-01-16 2 views
0

우리의 환경에서 Windows 버전과 .NET 설치의 폭이 넓어서 .NET을 필요로하지 않는 언어로 다음 C 날카로운 코드를 다시 작성해야합니다. 어쩌면 VBScript를 생각하고 있었지만이 포트를 얼마나 쉽게 사용할 수 있을지 모르겠습니다. 간단한 VBScript를 솔루션을 요구하는 경우단순한 디렉토리 루핑을 재 작성하는 C vbscript의 날카로운 코드?

 try 
     { 
      string docsDir = Environment.GetFolderPath(Environment.SpecialFolder.Mydocuments); 

      if (Directory.Exists(docsDir)) 
      { 
       // get all folders 
       DirectoryInfo dInfo = new DirectoryInfo(docsDir); 
       DirectoryInfo[] dirs = dInfo.GetDirectories(); 

       // start process 
       Process p = new Process(); 
       ProcessStartInfo info = new ProcessStartInfo(); 
       info.FileName = "cmd.exe"; 
       info.RedirectStandardInput = true; 
       info.RedirectStandardOutput = false; 
       info.CreateNoWindow = true; 
       info.UseShellExecute = false; 

       p.StartInfo = info; 
       p.Start(); 

       using (StreamWriter sw = p.StandardInput) 
       { 
        if (sw.BaseStream.CanWrite) 
        { 
         foreach (DirectoryInfo dir in dirs) 
         { 
          sw.WriteLine("FixPerms.exe" + dir.Name); 
         } 
        } 
       } 
      } 
      return true; 
     } 
     catch 
     { 
      return false; 
     } 
    } 
+1

그냥 생각해보십시오. .NET 2.0 또는 그 이하로 다운 그레이드 할 수 있습니까? (사실, 일반적으로 최신 .NET을 사용하는 컴퓨터는 이전 코드를 실행할 수 있습니다)? 또는. NET이 전혀없는 컴퓨터가 있습니까? – Gerino

+1

귀하의 질문은 무엇입니까? 포트를 넘기는 것이 얼마나 쉬운가요? 이것은 매우 간단하게 보입니다 ... 배치/.cmd로 쉽게 할 수 있습니다. –

+0

@ Gerino 불행히도 일부 컴퓨터에는 전혀 설치되어 있지 않지만 다른 컴퓨터에서는 Windows 8을 실행하고 있으므로 (기본적으로) .NET 4.5 코드 만 실행됩니다. – user4344582

답변

0

,이

Set fso = CreateObject("Scripting.FileSystemObject") 
Set f = fso.GetFolder(server.mappath(path)) 
Set sf = f.SubFolders 
for each fo in sf 

가 뭔가

next 
0

이것은 .cmd (또는 .bat) 파일을 사용하여 트릭을 할해야를 수행 도움이 될 수 있습니다, 모든 Windows 시스템에서 작동해야합니다.

@ECHO OFF 
SETLOCAL 

:: Set exit code to a failure code 
SET /A EXITCODE=-1 

:: Get the MyDocuments Folder 
FOR /F "skip=2 tokens=3" %%A IN ('REG.exe query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Personal"') DO (
    CALL :SetDocuments %%A 
) 

:: If MyDocuments doesn't exist, exit 
IF NOT EXIST "%MyDocuments%" GOTO :END 

:: Run the FixPerms.exe tool on each directory 
FOR /F "tokens=*" %%A IN ('DIR /B /AD "%MyDocuments%"') DO (
    CALL :RunProgramOnDirectory %%A 
) 

:: Set exit code to success 
SET /A EXITCODE=0 

:END 
ENDLOCAL&EXIT /B %EXITCODE% 

:SetDocuments 
SET MyDocuments=%* 
GOTO :EOF 

:RunProgramOnDirectory 
SET directoryName=%* 
START /MIN CMD.exe /C FixPerms.exe "%directoryName%" 
GOTO :EOF 
+0

누구나 .bat/.cmd에 대한 코드 샘플을 채색하는 방법을 알고 계십니까? –