D
D
dinaff2020-02-20 19:31:38
cmd/bat
dinaff, 2020-02-20 19:31:38

How to find files by owner and time after they were created?

I'll go straight to the point.

OS: Windows
Task:
Given a directory hierarchy. We are given the absolute address of one of the directories. It is necessary to find in this directory all files by def. template belonging to def. user, and time after creation, which are more than 2 days. Implement either as a bat script or as a command pipeline.
Trying to solve:
1. Pattern search was done with where /r abs the path we were given [pattern]. This way I got the absolute addresses of all files that match my pattern.
2. Search for the owner thought to do either through dir / q | find "username" or via cacls "path to file" | find
"username". The first option is not very good, since the file path entry may contain the username substring,
3.Time after creation. It seems to be solved by parsing the result of the dir command and then dancing with a tambourine
4. Ultimately, in order to copy, I need to know the absolute path and file name.

The main problem is in points 2 and 3.
Does anyone have any ideas how to deal with this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dinaff, 2020-02-20
@dinaff

Decided points 1,2,4.

forfiles /p [Путь где ищем] /d -[кол-во дней] /m [маска] /s /c "cmd /c copy @path [Путь куда вставляем]@file"

Example
forfiles /p homework /d -2 /m *.txt /s /c "cmd /c copy @path D:\good\@file"

Any idea how to check if a file belongs to a user?
UPD:
Crutch. But should work
forfiles /p [Путь поиска] /d -[кол-во дней] /m [маска] /s /c "cmd /c dir /q @path | find \"%computername%\%username%\" && copy @path [Путь для вставки]@file"

Example
forfiles /p homework /d -2 /m *.txt /s /c "cmd /c dir /q @path | find \"%computername%\%username%\" && copy @path D:\good\@file"

Cons:
Couldn't implement creating a new file when copying if the file already exists

K
Karpion, 2020-02-20
@Karpion

W'10 has a Linux subsystem, and it has a find program. What you want is there "out of the box".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question