wsh

How to change file attributes programmatically

There're many ways to change file attributes. It can be done through Windows Explorer, DOS ATTRIB comand, third party utilites, e.t.c. Also it can be done programmatically using Windows Scripting Host (WSH) or/and Windows API.

Generate GUID

UDF below generates 128-bit GUID and returns it as a string in the format 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.

MSDN:

Creating directory preserving name case

MSDN:

Returning UNC Path associated with a local device

MSDN links:

This is sample code. Add error handling and adjust to your requirements as necessary.

* Windows API
FUNCTION LocalDevice2UNC(tcLocalName)
LOCAL lcUNCBuffer, lnLength, lcLocalName, lcRemoteName
DECLARE INTEGER WNetGetConnection IN WIN32API ;
	STRING lpLocalName, STRING @ lpRemoteName, INTEGER @ lplnLength
IF TYPE('tcLocalName') <> "C" OR EMPTY(tcLocalName) 
	ERROR 11
ENDIF

File date and time

Code below shows how to retrieve file date and time using native VFP commands or WSH. For Windows API based solution that also allows to set file date and time, see George Tasker's Windows Time hosted on UT

MSDN links:

Copy, Move, Rename File Preserving Destination Name Case

The CopyFile() and MoveFile() WIN API functions preserve the case of the name for the destination file. Alternatively, WSH can be used.
The source and destination file names should include the directory name in both cases.

Note 1 A Copy operation will not change file name case when destination file already exists (overwritten).

Note 2 The WinApiErrMsg is used to retrieve Windows API error message in case of error.

This is sample code. Add error handling and adjust to your requirements as necessary.

 
Syndicate content