Iska
30-09-2014, 05:15
WSH:
Option Explicit
Dim strSourceFolder
Dim objFSO
Dim objFile
Dim strFormatCurrDate
strSourceFolder = "E:\Песочница\0399"
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strSourceFolder) Then
strFormatCurrDate = Right("00" & CStr(Month(Date())), 2) & Right("00" & CStr(Day(Date())), 2)
With WScript.CreateObject("VBScript.RegExp")
.IgnoreCase = True
.Pattern = "(.*#)(.*)(#.*\.txt)"
For Each objFile In objFSO.GetFolder(strSourceFolder).Files
If .Test(objFile.Name) Then
objFile.Name = Replace(.Replace(objFile.Name, "$1" & ":" & "$3"), ":", strFormatCurrDate)
End If
Next
End With
Else
WScript.Echo "Can't find source folder [" & strSourceFolder & "]."
WScript.Quit 1
End If
Set objFSO = Nothing
WScript.Quit 0
PoSH:
$sSourceFolder = "E:\Песочница\0399"
$sMask = "(.*#)(.*)(#.*\.txt)"
if(Test-Path -Path $sSourceFolder -PathType Container) {
$sFormatCurrDate = Get-Date -Format "MMdd"
Get-ChildItem -Path $sSourceFolder |`
ForEach-Object -Process {
if(!$_.PSIsContainer) {
if($_.Name -match $sMask) {
Rename-Item -Path $_.FullName -NewName ($_.Name -replace $sMask, '$1:$3').replace(":", $sFormatCurrDate)
}
}
}
} else {
Write-Host "Can't find source folder [$sSourceFolder]." -ForegroundColor Red
}
CMD:
@echo off
setlocal enableextensions enabledelayedexpansion
set sSourceFolder=E:\Песочница\0399
if exist "%sSourceFolder%\." (
call :GetFormatDateTime
pushd "%sSourceFolder%"
for /f "usebackq delims=" %%i in (
`2^>nul dir /b /a:-d "%sSourceFolder%\*.*" ^| findstr.exe ".*#.*#.*\.txt"`
) do (
set sOldName=%%~i
call :GetNewName "!sOldName:#=" "!"
ren "%%~i" "!NewName!"
)
popd
) else (
echo Can't find source folder [%sSourceFolder%].
exit /b 1
)
endlocal
exit /b 0
rem ==========================================================================
rem ==========================================================================
:GetNewName
setlocal enableextensions enabledelayedexpansion
set sProcName=%~0
endlocal & set %sProcName:~4%=%~1#%FormatDateTime%#%~3
exit /b 0
rem ==========================================================================
rem ==========================================================================
rem Функция GetFormatDateTime()
rem
rem Серый форум (http://forum.script-coding.com)
rem ==========================================================================
:GetFormatDateTime
setlocal enableextensions enabledelayedexpansion
set sProcName=%~0
for /f "delims=." %%i in ('wmic.exe OS get LocalDateTime ^| find "."') do set sDateTime=%%i
endlocal & set %sProcName:~4%=%sDateTime:~4,4%
exit /b 0
rem ==========================================================================
Option Explicit
Dim strSourceFolder
Dim objFSO
Dim objFile
Dim strFormatCurrDate
strSourceFolder = "E:\Песочница\0399"
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strSourceFolder) Then
strFormatCurrDate = Right("00" & CStr(Month(Date())), 2) & Right("00" & CStr(Day(Date())), 2)
With WScript.CreateObject("VBScript.RegExp")
.IgnoreCase = True
.Pattern = "(.*#)(.*)(#.*\.txt)"
For Each objFile In objFSO.GetFolder(strSourceFolder).Files
If .Test(objFile.Name) Then
objFile.Name = Replace(.Replace(objFile.Name, "$1" & ":" & "$3"), ":", strFormatCurrDate)
End If
Next
End With
Else
WScript.Echo "Can't find source folder [" & strSourceFolder & "]."
WScript.Quit 1
End If
Set objFSO = Nothing
WScript.Quit 0
PoSH:
$sSourceFolder = "E:\Песочница\0399"
$sMask = "(.*#)(.*)(#.*\.txt)"
if(Test-Path -Path $sSourceFolder -PathType Container) {
$sFormatCurrDate = Get-Date -Format "MMdd"
Get-ChildItem -Path $sSourceFolder |`
ForEach-Object -Process {
if(!$_.PSIsContainer) {
if($_.Name -match $sMask) {
Rename-Item -Path $_.FullName -NewName ($_.Name -replace $sMask, '$1:$3').replace(":", $sFormatCurrDate)
}
}
}
} else {
Write-Host "Can't find source folder [$sSourceFolder]." -ForegroundColor Red
}
CMD:
@echo off
setlocal enableextensions enabledelayedexpansion
set sSourceFolder=E:\Песочница\0399
if exist "%sSourceFolder%\." (
call :GetFormatDateTime
pushd "%sSourceFolder%"
for /f "usebackq delims=" %%i in (
`2^>nul dir /b /a:-d "%sSourceFolder%\*.*" ^| findstr.exe ".*#.*#.*\.txt"`
) do (
set sOldName=%%~i
call :GetNewName "!sOldName:#=" "!"
ren "%%~i" "!NewName!"
)
popd
) else (
echo Can't find source folder [%sSourceFolder%].
exit /b 1
)
endlocal
exit /b 0
rem ==========================================================================
rem ==========================================================================
:GetNewName
setlocal enableextensions enabledelayedexpansion
set sProcName=%~0
endlocal & set %sProcName:~4%=%~1#%FormatDateTime%#%~3
exit /b 0
rem ==========================================================================
rem ==========================================================================
rem Функция GetFormatDateTime()
rem
rem Серый форум (http://forum.script-coding.com)
rem ==========================================================================
:GetFormatDateTime
setlocal enableextensions enabledelayedexpansion
set sProcName=%~0
for /f "delims=." %%i in ('wmic.exe OS get LocalDateTime ^| find "."') do set sDateTime=%%i
endlocal & set %sProcName:~4%=%sDateTime:~4,4%
exit /b 0
rem ==========================================================================