1. FileSystem examples

This page includes some simple examples of basic usage of the pyxrootd FileSystem object to interact with an xrootd server.

We’ll use the following imports and FileSystem object as the basis for the rest of the examples:

from XRootD import client
from XRootD.client.flags import DirListFlags, OpenFlags, MkDirFlags, QueryCode

myclient = client.FileSystem('root://someserver:1094')

1.1. Copy a file

status = myclient.copy('/tmp/spam', '/tmp/eggs', force=True)
assert status.ok

See XRootD.client.CopyProcess if you need multiple/more configurable copy jobs.

1.2. Ask a for a directory listing

status, listing = myclient.dirlist('/tmp', DirListFlags.STAT)

print listing.parent
for entry in listing:
  print "{0} {1:>10} {2}".format(entry.statinfo.modtimestr, entry.statinfo.size, entry.name)

Produces output similar to the following:

2013-04-12 09:46:51         20 spam
2013-04-05 08:23:00       4096 .xrootd
2013-04-12 09:33:25         20 eggs

1.3. Make a directory

myclient.mkdir("/tmp/some/dir", MkDirFlags.MAKEPATH)

1.4. Delete a directory


1.5. Move/rename a file

myclient.mv("/tmp/spam", "/tmp/eggs")

1.6. Delete a file


1.7. Locate a file

status, locations = myclient.locate("/tmp", OpenFlags.REFRESH)

print locations

Produces output similar to the following:

<locations: [<type: 2, address: '[::]:1094', accesstype: 1, is_manager: False, is_server: True>]>

1.8. Ask the server for some information

status, response = myclient.query(QueryCode.SPACE, '/tmp')

print response

Produces output similar to the following:


For more information about XRootD query codes and arguments, see the relevant section in the protocol reference.