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

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

Ветеран


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

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


Цитата balzaman:
но, при отмене создания файла, возникает ошибка »
Скрытый текст
Код: Выделить весь код
Option Explicit

Dim strSourceFile


With WScript.CreateObject("Scripting.FileSystemObject")
	strSourceFile = Trim(InputBox("Enter file name:", "Enter file name", .GetAbsolutePathName(GetLocalDate() & ".txt")))
	
	If Len(strSourceFile) > 0 Then
		If Not .FileExists(strSourceFile) Then
			.CreateTextFile(strSourceFile).Close
			WScript.CreateObject("Shell.Application").NameSpace(.GetParentFolderName(strSourceFile)).ParseName(.GetFileName(strSourceFile)).InvokeVerb "open"
		End If
	End If
End With

WScript.Quit 0

Function GetLocalDate()
	Dim objSWbemObjectEx
	
	For Each objSWbemObjectEx In WScript.CreateObject("WbemScripting.SWbemLocator").ConnectServer(".", "root\cimv2").ExecQuery("SELECT LocalDateTime FROM Win32_OperatingSystem WHERE Primary = 'True'")
		GetLocalDate = Left(objSWbemObjectEx.LocalDateTime, 8)
		
		Exit For
	Next
End Function


Цитата balzaman:
а можно такой же скрипт для создания каталога (папки) »
Скрытый текст
Код: Выделить весь код
Option Explicit

Dim strSourceFolder


With WScript.CreateObject("Scripting.FileSystemObject")
	strSourceFolder = Trim(InputBox("Enter folder name:", "Enter folder name", .GetAbsolutePathName(GetLocalDate())))
	
	If Len(strSourceFolder) > 0 Then
		If Not .FolderExists(strSourceFolder) Then
			.CreateFolder strSourceFolder
			WScript.CreateObject("Shell.Application").Open strSourceFolder
		End If
	End If
End With

WScript.Quit 0

Function GetLocalDate()
	Dim objSWbemObjectEx
	
	For Each objSWbemObjectEx In WScript.CreateObject("WbemScripting.SWbemLocator").ConnectServer(".", "root\cimv2").ExecQuery("SELECT LocalDateTime FROM Win32_OperatingSystem WHERE Primary = 'True'")
		GetLocalDate = Left(objSWbemObjectEx.LocalDateTime, 8)
		
		Exit For
	Next
End Function
Это сообщение посчитали полезным следующие участники:

Отправлено: 00:59, 02-10-2019 | #6