Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0125-preview· OpenAIAi2 WildChat-4.8M (AI2)

@echo off SETLOCAL for %%i in (*.pdf) do "C:\Program Files…

  1. User

    @echo off SETLOCAL for %%i in (*.pdf) do "C:\Program Files (x86)\gs\gs10.03.0\bin\gswin32c.exe" -q -dNOPAUSE -sDEVICE=txtwrite -sOutputFile="%%~ni.txt" -dFirstPage=1 -dLastPage=1 "%%i" -c quit echo Conversion Complete! ENDLOCAL for this i want to show an option to choose pdf files

  2. Assistant

    To provide an option to choose specific PDF files instead of automatically converting all PDF files in a directory, we'll need to modify the script slightly. In a command line environment like a batch file, there's no native, simple way to create a graphical user interface for file selection. However, we can achieve a basic selection mechanism by using a combination of command-line prompts and inputs.

    The revised script will:

    1. List all PDF files in the current directory with numbers.
    2. Allow the user to enter the numbers of the files they wish to convert (comma-separated or space-separated).
    3. Parse the user's selection, and then proceed with the conversion for the selected files.

    Here's a script with these modifications:

    @echo off
    SETLOCAL ENABLEDELAYEDEXPANSION
    
    :: List and number all PDF files
    echo Available PDF files:
    set /a count=0
    for %%i in (*.pdf) do (
        set /a count+=1
        echo !count!. %%i
        set "file!count!=%%i"
    )
    
    :: Ask user for selection
    echo.
    set /p "userInput=Enter the numbers of the PDF files you want to convert (comma or space separated): "
    echo.
    
    :: Parse user input and convert files
    FOR %%A IN (%userInput%) DO (
        set /a fileNum=%%A
        set "fileName=!file!fileNum!"
        
        if not "!fileName!"=="" (
            echo Converting file: !fileName!
            "C:\Program Files (x86)\gs\gs10.03.0\bin\gswin32c.exe" -q -dNOPAUSE -sDEVICE=txtwrite -sOutputFile="!fileName:~0,-4!.txt" -dFirstPage=1 -dLastPage=1 "!fileName!" -c quit
        ) else (
            echo Invalid selection: %%A
        )
    )
    
    echo Conversion Complete!
    
    ENDLOCAL
    

    This script provides a basic user interaction mechanism for selecting specific PDF files for conversion. Please note the following:

    • The script lists all PDF files and asks for input. Users should enter the numbers corresponding to the files they wish to convert, separated by commas or spaces (e.g., 1,3,5 or 1 3 5).
    • The conversion tool path ("C:\Program Files (x86)\gs\gs10.03.0\bin\gswin32c.exe") and its parameters are kept the same. Ensure this path matches the actual location of your Ghostscript installation.
    • The !fileName:~0,-4!.txt in the script dynamically creates the output file name by stripping the last 4 characters (the .pdf extension) off the input file name and appending .txt instead.
    • Error handling is minimal; for example, invalid input like entering letters instead of numbers will not be properly handled in this script.

    Remember, this example assumes a simple use case and may need adjustments for your specific needs, such as more sophisticated error checking or handling files with special characters in their names.