Drive.File.Operation

Prev Next

Type

Read/write

Author

Availability

Data provider

Write

Finbourne

Provided with LUSID

The Drive.File.Operation provider enables you to write a Luminesce query that performs the following operations upon files in Drive:

  • Delete

  • MoveRename

  • MoveRenameMayOverwrite

  • Copy

  • CopyMayOverwrite

Note the similar Sftp.File.Operation provider adds the following operations to copy files between an SFTP server and Drive in a single query:

  • CopyFromDrive

  • CopyFromDriveMayOverwrite

  • CopyToDrive

  • CopyToDriveMayOverwrite

See also: Drive.File, Drive.SaveAs

Basic usage

@data = select <file-paths-and-operation>;
select * from Drive.File.Operation
  where and UpdatesToPerform = @data;

Query parameters

Drive.File.Operation has a single mandatory UpdatesToPerform parameter that encapsulates the files and operation to perform.

Basic usage

By default, Drive.File.Operation returns a table of data populated with particular fields (columns). You can return just a subset of these fields if you wish.

To list fields available to return, their data types, whether fields are considered 'main', and an explanation for each, run the following query using a suitable tool:

select FieldName, DataType, IsMain, IsPrimaryKey, SampleValues, Description from Sys.Field where TableName = 'Drive.File.Operation' and FieldType = 'Column';

Examples

Note: For more examples, try the Luminesce Github repo.

Example 1: Move a file into a new folder

Any folders specified in NewFullPath are created if they do not already exist.

If you do not want existing files to be overwritten, specify 'MoveRename' as Operation instead.

@data = select 
  '/luminesce/testing/myfile.csv' as FullPath,
  '/luminesce/my-new-folder/myfile.csv' as NewFullPath,
  'MoveRenameMayOverwrite' as Operation;

select * from Drive.File.Operation
  where UpdatesToPerform = @data; 

Example 2: Rename a file

Note the filename and path are case-sensitive.

@data = select 
  '/myfile.csv' as FullPath,
  '/myrenamedfile.csv' as NewFullPath,
  'MoveRenameMayOverwrite' as Operation;

select * from Drive.File.Operation
  where UpdatesToPerform = @data; 

Example 3: Rename multiple files

You can specify one or more rows in UpdatesToPerform to move, rename or delete multiple files in one call.

@files_to_rename = values
('/myfile.csv', '/myrenamedfile.csv'),
('/myotherfile.csv', '/myotherrenamedfile.csv');

@table_of_data = select 
  column1 as FullPath, 
  column2 as NewFullPath, 
  'MoveRenameMayOverwrite' as Operation from @files_to_rename;

select * from Drive.File.Operation
  where UpdatesToPerform = @table_of_data; 

Example 4: Delete a file

@data = select 
  '/myfile.csv' as FullPath,
  'Delete' as Operation;

select * from Drive.File.Operation
  where UpdatesToPerform = @data;