0

This is the test code for my program. The program gets all the files with the file extension .txt opens it then does tasks and then saves the file as a .pdf

@setlocal enableextensions enabledelayedexpansion
@ECHO OFF
set test = hi
for /R  %%f in (*.txt) do (
  @echo %%f
  echo test =  "%%f"
  set test =  "%%f"
  echo %test%
  set test =!test:~0,-4!
  echo !test!
  )
  pause
)
endlocal

pause

Because in the program there is a specific way to export I am sending the file name to the usual save window using SendKeys in a VBS script. I am trying to remove the file extension but it is not working. I just get Echo is off because the variable wont set properly

I also tried this

setlocal enabledelayedexpansion
@echo off
set variable = 
for /R %%f in (*.vc6) do (
  @echo %%f 
  FOR /F "delims=" %%i IN ("%%f") DO (
    ECHO filedrive=%%~di
       SET filedrive=%%~di

    ECHO filepath=%%~pi
    SET filepath=%%~pi   
    ECHO filename=%%~ni

    set filename=%%~ni 
    ECHO fileextension=%%~xi

    ECHO !fileextension!
    set noext = %%filedrive%%%%filepath%%%%filename%%
    ECHO !noext!

  )
  pause
)
endlocal

pause

But I still get the same output of echo is off. Ideally I could get the second one working because I need to save it in a different folder

Before this is marked as a duplicate because there do seem to be others like this. I have looked through them and nothing has worked.

aschipfl
  • 28,946
  • 10
  • 45
  • 77
  • 5
    Remove all spaces surrounding `=` in `set` command. For instance, `set test = "%%f"` defines variable `%test %`. Use `set "test=%%f"` instead. – JosefZ May 21 '18 at 17:48
  • Worked for the first one going to test the second and things like that are why I am not going into comp sci or things that are coding intensive – erhamm99 May 21 '18 at 19:24
  • Simply use `set "noext=%%~dpnf"` omitting the inner `%%i` loop at all. – JosefZ May 21 '18 at 19:48

0 Answers0