1

According to my previous question i found a solution for my problem.prev Question

I have written my script but i moved it to my server and i was surprised because the script does not working anymore. I made a new one only for testing and the solution from the previous question is not anymore workable!

Here is my test script

@echo off
TITLE MyBatch
SETLOCAL ENABLEDELAYEDEXPANSION

set "merger_list=C:\"
set "source=C:\ASAP2-Build\Input"
set "target=C:\ASAP2-Build\Output"

:loop
Rem this "for" loop executed for all folders in source path. /ad -> folder. /o:d -> sorted by date and time. /s -> include all subfolders. /b -> bare format
 for /f %%i in ('dir %source% /ad /o:d /s /b') do (
        rem command.merging is an empty file which works as a command. We use it to triger the merging function.
        if exist %%i\command.merging (
            rem a2lfiles_merger is a text file with a list, this list includes all the slave a2l files into a list to merging.
           if exist %%i\a2lfiles_merger*.txt (
             rem this loop have to find the complete name of the a2lfiles_merger. Will be f.ex. a2lfiles_merger2.txt 
                for /f "tokens=*" %%d in ('dir /b /s   a2lfiles_merger*.txt') do ( 
                set merger_list=%%d
                echo !merger_list!
                )
            
            )
        )
        
    )
echo Folder is empty or does not exist
timeout /t 5
goto loop

The problem occurs when i call this line

for /f "tokens=*" %%d in ('dir /b /s a2lfiles_merger*.txt') do ( 
                set merger_list=%%d
                echo !merger_list!
                )

The screen prints the message Das System kann die angegebene Datei nicht finden. The translation is The system cannot find the file.

I have to explain why i need this code, in every folder there is always a txt file with an unknown name but always in form a2lfiles_merger*.txt. Some folders have the file a2lfiles_merger2.txt and others a2lfiles_merger3.txt etc.

So it is so dificult to me to understand why this script runs at my computer and not at my server. The server has also windows 7. Have someone a suggestion ?

Community
  • 1
  • 1
pop rock
  • 517
  • 1
  • 6
  • 14
  • @jeb I am not sure if i understand you, but i try to check if the txt file exist, if not i have an error. If the list exist, i try to retrieve the whole of the name. When i have the name i call the program but in this test script i do nothing more. – pop rock Aug 05 '15 at 07:52
  • @jeb `if exist` **does** accept wildcards. However, I'd use (note no `/s` switch bu full path instead) `for /f "tokens=*" %%d in ('dir /ad /b "%%i\a2lfiles_merger*.txt"') do (` followed by `set "merger_list=%%i\%%d"` line and then `echo !merger_list!)` line... – JosefZ Aug 05 '15 at 07:57
  • Sorry, I was wrong, `if exist` CAN use wildcards, but even then you should enclose your filenames in quotes, like `if exist "%%i\a2lfiles*" (` to avoid confusion with spaces. You should add `ECHO` commands at many lines to get the real problem – jeb Aug 05 '15 at 07:58
  • 1
    ...or remove `@echo off` and review every echoed line... – aschipfl Aug 05 '15 at 08:22
  • this is th e final version which working for me!! Thank you `if exist "%%i\a2lfiles_merger*" ( for /f "tokens=*" %%d in ('dir /b "%%i\a2lfiles_merger*.txt" ') do (set merger_list=%%i\%%d )` – pop rock Aug 05 '15 at 09:22
  • Oh yes, I passed over wrong `/AD` switch contradicting the `*.txt` file attribute... – JosefZ Aug 05 '15 at 12:33

1 Answers1

0

Right there at the beginning - you have quotes in the wrong place:

set "merger_list=C:\"

Shouldn't that be:

set merger_list="C:\"

That's a bad start ;)

ClioCJS
  • 64
  • 3
  • 11
  • Look the second answer of this question http://stackoverflow.com/questions/10552812/declaring-and-using-a-variable-in-dos-windows-batch-file-bat I think you dont have right! – pop rock Aug 14 '15 at 09:53