2017-10-24 3 views
0

나는이처럼 작동하도록되어 배치 파일이 : 텍스트가 줄을 삭제 발견되면 특정 txt 파일에 대한윈도우 컨텍스트 메뉴 및 일괄 -> 편집 선택한 파일

  • 검색
  • 포함 2 이상의 공백이 있으면 텍스트는
  • 특정 일

Basicaly I 편집에

  • 변경 파일 확장자 한 공간을 convertem 다른 프로그램에서 생성 된 파일을 변환하여 내 프로그램에서 읽을 수 있도록합니다. (매번 다른 이름과 확장명을 가짐)

    나는 새로운 txt 파일을 만들고 원래 파일에서 & 붙여 넣기를 txt 파일로 복사 한 다음 배치 파일을 실행합니다.

    원래 파일을 마우스 오른쪽 버튼으로 클릭하고 파일을 변환 할 수 있도록 새 파일을 만들고 배치 파일을 Windows 컨텍스트 메뉴에 추가하는 부분을 건너 뛰고 싶습니다. 하지만 편집 할 원본 파일을 설정하는 방법을 모릅니다.

    Curent 코드를 (또한 나는 윈도우 XP에서 실행해야합니다) :

    @ECHO OFF 
    setlocal enabledelayedexpansion 
    
    ::Create txt file 
    set "fisiertxt=%CD%\New Text File.txt" 
    if not exist "%fisiertxt%" REM. > "New Text File.txt" 
    
    ::Start txt file 
    start notepad "New Text File.txt" 
    
    ::check if file is still open 
    :verifica 
    tasklist /FI "IMAGENAME eq Notepad.exe" 2>NUL | find /I /N "Notepad.exe" >NUL 
    if "%ERRORLEVEL%"=="1" goto Aici 
    goto verifica 
    
    ::Delete file if its empty 
    :Aici 
    
    >nul findstr "^" "New Text File.txt" || del "New Text File.txt" 
    
    :: check if there are delimitators delete them 
    find /c "99999 0 0 0" "New Text File.txt" 
    if "%ERRORLEVELs%"=="1" goto FaraSeparator 
    pause 
    
    :: if yes make a new file winought them 
    
    
    set count=1 
    for /f "delims=" %%A in ('find /V /I "99999 0 0 0" "New Text File.txt"') do (
        if !count!==1 echo.>document.txt 
        if !count! GTR 1 echo %%A>>document.txt 
        set /A count=!count!+1) 
    
    
    
    :: 
    :: delete the exit file 
    :: delete the first row (the exit file has an emplty first row) 
    :: replace 2 or more spaces with 1 space 
    :: 
    
    DEL Drumuire.mnu 2>nul /F /Q 
    :: replace with -> 
    SET delim= 
    :: set number of lines to delete 
    FOR /f "skip=1delims=" %%i IN (document.txt) DO (
        SET line=%%i 
        (SET newline=) 
        SET count=0 
        CALL :SCHIMBARI 
    ) 
    
    GOTO :eof 
    
    :SCHIMBARI 
    SET c1=%line:~0,1% 
    SET line=%line:~1% 
    IF "%c1%"==" " (SET /a count+=1) ELSE (
        IF %count%==0 (SET newline=%newline%%c1%) ELSE (
         IF %count%==1 (SET newline=%newline% %c1%) ELSE (
          SET newline=%newline%%delim%%c1%) 
        SET count=0 
        ) 
    ) 
    IF DEFINED line GOTO SCHIMBARI 
    :: 
    :: You may want to preserve trailing spaces 
    :: or convert them... 
    :: 
    IF %count%==0 GOTO SCOATE 
    IF %count%==1 SET newline=%newline% &GOTO SCOATE 
    SET newline=%newline%%delim% 
    :SCOATE 
    >>Drumuire.mnu ECHO %newline% 
    DEL document.txt 
    goto done 
    :: 
    :: -------------------------------------------------------------------------- 
    :: 
    
    
    :winought delimitator 
    DEL Drumuire.mnu 2>nul /F /Q 
    :: replace with -> 
    SET delim= 
    :: set number of lines to delete 
    FOR /f "usebackq delims=" %%i IN ("New Text File.txt") DO (
        SET line=%%i 
        (SET newline=) 
        SET count=0 
        CALL :PRESCHIMBA 
    ) 
    
    GOTO :eof 
    
    :PRESCHIMBA 
    SET c1=%line:~0,1% 
    SET line=%line:~1% 
    IF "%c1%"==" " (SET /a count+=1) ELSE (
        IF %count%==0 (SET newline=%newline%%c1%) ELSE (
         IF %count%==1 (SET newline=%newline% %c1%) ELSE (
          SET newline=%newline%%delim%%c1%) 
        SET count=0 
        ) 
    ) 
    IF DEFINED line GOTO PRESCHIMBA 
    :: 
    :: You may want to preserve trailing spaces 
    :: or convert them... 
    :: 
    IF %count%==0 GOTO PRINT 
    IF %count%==1 SET newline=%newline% &GOTO PRINT 
    SET newline=%newline%%delim% 
    :PRINT 
    >>Drumuire.mnu ECHO %newline% 
    
    
    :done 
    
  • +0

    . 기본적으로 의사 코드를 게시하고 있습니다. 도움이 필요하면 사용중인 코드를 게시하십시오. – Squashman

    +0

    Ive는 내 코드를 추가하고 txt에 qoutes가 포함되어 있으면 오류가 있다는 것을 알아 냈습니다. shoudnt가 문제가 될 수는 있지만 단지 내가 메모를 추가해야합니다./ – Ionescu

    +0

    배치 파일 (또는 링크)을' % APPDATA % \ Microsoft \ Windows \ SendTo \'를 선택하십시오. 그런 다음 파일을 마우스 오른쪽 버튼으로 클릭하고 '보내기'를 선택한 다음 스크립트 또는 링크를 선택하십시오. 스크립트 안에'% 1'로 파일을 참조 할 수 있습니다. – Stephan

    답변

    0

    @Stephan이 코멘트에서 언급 한 바와 같이, 다음 단계를 사용하여 목표를 달성 할 수 있습니다.

    1 : 쓰기 배치 파일을 사용하여 매개 변수/인수 (docs)

    context.bat

    @echo off 
    rem set up a couple variables for easier modification 
    set "tfile=New Text File.txt" 
    set "searchstring=9999" 
    
    rem output some things for information purposes 
    echo Source File: %1 
    echo Target File: %tfile% 
    echo Target Folder: %cd% 
    
    rem copy the file 
    echo Copying file... 
    copy %1 "%tfile%" 
    
    rem check for the search string defined above 
    echo Checking for search string... 
    find /c "%searchstring%" "%tfile%" >NUL 
    if "%ERRORLEVEL%"=="0" GOTO FOUNDSTRING 
    if "%ERRORLEVEL%"=="1" GOTO NOTFOUND 
    
    :NOTFOUND 
    echo Did not find search string (%searchstring%) 
    GOTO ENDER 
    
    :FOUNDSTRING 
    echo Found search string (%searchstring%) 
    GOTO ENDER 
    
    :ENDER 
    rem remove the next line once everything is working so you don't have to press a key each time it runs 
    pause 
    

    2 : "보내기"윈도우에 추가

    copy context.bat %appdata%\Microsoft\Windows\SendTo 
    

    3 : 마우스 오른쪽 버튼을 클릭하고 보내기> context.bat, 이익! 배치 파일에서 실행하는 코드 같은 것을 보이지 않는

    You targeted D:\test\test.txt! 
    Press any key to continue . . . 
    
    +0

    이것은 Win10에서 잘 작동하며 regedit를 건너 뛰었습니다. Im gona는 나중에 XP sp3를 사용하여이 날 ​​테스트합니다. – Ionescu

    +0

    드래그 앤 드롭 기능도 사용할 수 있습니다. 대상 파일을 배치 파일로 끌어 올 수 있습니다. 이는 워크 플로우에 따라 더 나을 수 있습니다. –

    +0

    어쨌든 XP에서 제대로 작동하지 못했습니다. 필자는 이것을 시도했다 : "복사"% 1 ""새 텍스트 파일.txt " find/c"99999 0 0 0 ""New Text File.txt ""'(Im은 이것을 사용할 사람들이 "99999 0 0 0 "을 입력하고 여분의 공백을 모두 지우십시오.) – Ionescu