0

I want to do echo only checking the date from one file with forfiles:

forfiles /m "C:\Backups\TEST.bak" /c "cmd /c echo test" /d -1

But it returns me an error:

The System cannot find the file specified.

And that file it exists and the directory is correct.

If use forfiles in the same directory (without file) it works fine:

forfiles /p "C:\Backups" /c "cmd /c echo test" /d -1

What am I doing wrong?

2 Answers 2

3
forfiles /p "c:\Backups" /m "test.bak" /d -1 /c "cmd /c echo @fdate @ftime"

/p needs a folder to start searching

/m needs a file mask to indicate what to search

Sign up to request clarification or add additional context in comments.

7 Comments

And If I want to do a callback, What I should do?
@mac94, sorry, I don't understand the question. Please, can you explain what do you want to obtain?
I would like to replace the echo and to do a callback. In my batch file call to :end.
And if I use with /d -1 I will check if the file has more than one day.
@mac94, you can't do it. The code is running in a separate cmd instance that knows nothing about the target label in the current batch file. Maybe there are other solutions, but comments are not a good place to include requirements and expose solutions. Can you start a new question?
|
1

The problem is that forfiles requires a directory as parameter. You are giving it a file instead. This won't work.

Instead you should do this:

FOR %%a in (C:\Backups\TEST.bak) DO SET FileDate=%~ta

This will store the file's modifed date in %FileDate%.

2 Comments

Sorry, the : from the path was in my code, but not in the post.
I want to use the forfiles because with that I can check if the file has more than one day.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.