0

There are some files with extension .out in a folder. They can be opened as text. The contents of some of these files start by the character 0. I want to move them to a dedicated folder (named zero) using a Windows batch command.

I tried the following:

@echo off
setlocal EnableDelayedExpansion
for %%x in (*.out) do (set /p y=< "%%x" & echo !y! & if !y:~0,1!==0 move "%%x" "zero")

but it does not work... How to do that?

  • 3
    You didn't separate the commands. Either `... do ((set /p y=< "%%x" & echo !y! & if !y:~0,1!==0 move "%%x" "zero")` or write them on different physical lines (which enhances readability) – Stephan Jan 05 '23 at 08:35
  • @Stephan: the code was modified according to your comment, but it still does not work. – Sebastien Palcoux Jan 05 '23 at 08:47
  • 1
    does it at least echo `!y!` correctly? – Stephan Jan 05 '23 at 08:50
  • @Stephan I am not sure to understand your question. What is it? How can I check that it echo !y! correctly? – Sebastien Palcoux Jan 05 '23 at 08:53
  • 2
    Use recommended (quoted) syntax `if "!y:~0,1!" == "0"` – Stephan Jan 05 '23 at 08:56
  • I think what Stephan wanted to know is whether `echo !y!` returns the output you expect, which you can only see when you run your batch file by opening a Command Prompt window, manoeuvring to the parent directory of the script (using `cd`) and typing the name of the script, rather than just double-clicking it's icon… – aschipfl Jan 05 '23 at 16:14

0 Answers0