Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8087

Профиль | Отправить PM | Цитировать


Busla, forfiles работает не с датой/временем создания.

Цитата flesh_royal1:
Неужели не существует более краткого решения? »
Более краткое решение :lol:
Код: Выделить весь код
@echo off
setlocal enableextensions enabledelayedexpansion

set sSourceFolder=%~1
set sDestFolder=%~2
set sDateCreatedBefore=%~3

for %%i in ("sSourceFolder" "sDestFolder" "sDateCreatedBefore") do if not defined %%~i (
	call :Usage
	exit /b 1
)

if not exist "%sSourceFolder%\." (
	echo Can't find source folder [%sSourceFolder%].
	exit /b 2
)

if not exist "%sDestFolder%\." (
	echo Can't find destination folder [%sDestFolder%].
	exit /b 3
)

echo %sDateCreatedBefore%|>nul 2>&1 findstr.exe /r /b /e /c:"[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9]" || (
	echo Third parameter [%sDateCreatedBefore%] probably not a date in DD.MM.YYYY template.
	exit /b 4
)

set sSourceDrive=%sSourceFolder:~0,2%
set sSourcePath=%sSourceFolder:~2%\
set sDateCreatedBefore4Wbem=%sDateCreatedBefore:~6,4%%sDateCreatedBefore:~3,2%%sDateCreatedBefore:~0,2%

for /f "usebackq delims=" %%i in (
	`2^>nul wmic.exe DataFile where "Drive='%sSourceDrive%' AND Path = '%sSourcePath:\=\\%' AND CreationDate < '%sDateCreatedBefore4Wbem%'" get Name /value ^| 2^>nul find.exe /i "Name="`
) do for /f "tokens=2 delims==" %%j in ("%%~i") do (
	call :CopyFile "%%~j"
)

endlocal
exit /b 0

:Usage
	echo Usage: %~nx0 ^<Source folder^> ^<Destination folder^> ^<Date created before^>
	exit /b

:CopyFile
	setlocal enableextensions enabledelayedexpansion

	set sSourceFile=%~1

	for /f "usebackq delims=" %%i in (
		`2^>nul wmic.exe DataFile "%sSourceFile:\=\\%" get CreationDate /value ^| 2^>nul find.exe /i "CreationDate="`
	) do for /f "tokens=2 delims==+-." %%j in ("%%~i") do (
		set sCreationDate=%%~j
		set sNewFileName=%~n1_!sCreationDate:~0,8!%~x1
		
		echo Copy source file [%sSourceFile%] into destination folder [%sDestFolder%] as [!sNewFileName!]
		>nul copy /y "%sSourceFile%" "%sDestFolder%\!sNewFileName!"
	)

	endlocal
	exit /b 0

Цитата flesh_royal1:
Спасибо, решение было получено с использованием && »
К сожалению, это не то решение, что требовалось в задании.

P.S. Скажите Вашему преподавателю, что он извращенец альтернативно одарённый человек — давать такие лабораторки бедным студентам.

P.P.S. А если он примет решение с forfiles — то ещё и лопух .

P.P.P.S. WSH, PowerShell — наше всё в данном случае.

Последний раз редактировалось Iska, 18-10-2018 в 00:35.

Это сообщение посчитали полезным следующие участники:

Отправлено: 00:19, 18-10-2018 | #4