---
schema_version: "1"
id: 21f4c885c54c86238b57404c49e45f37699b4f89e7254403f4de6c0911efd0ba
title: RenameFile.ds
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/commerce-cloud/b2c-commerce/guides/inventory/b2c-rename-file-ds.md
canonical_url: https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/b2c-rename-file-ds.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: a3510b831d3c75090978c0a59bb5b76790c24731e6d2fef386d42e6fdd97bfd4
products:
  - Composable Storefront
  - Salesforce APIs
---
# RenameFile.ds

Review the RenameFile.ds referenced script files when scheduling inventory imports.

**note:** This code is provided as a sample. It isn't a supported part of the SiteGenesis application.

```
/**
 * Moves a file to another directory.
 *
 * @input SourceFileName  : String   		the file to move
 * @input TargetFileName  : String   		the file to move
 * @input SourceDirectory : dw.io.File   		the processing directory where the file is located
 * @input TargetDirectory : dw.io.File   		the target processing directory
 * @input sampleLogger    : Object Sample logger	input for Sample logger
 * @input Status  	  : dw.system.Status 	The stautus of the DW import pipelet
 * @output TargetFile	  : dw.io.File
 * @output sampleLogger   : Object Sample logger	debug output for Sample logger
 * @output sampleError 	  : Object Sample error	error output for Sample logger
 */
importPackage(dw.system);
importPackage(dw.io);



importScript("bc_sample:library/impex/libImpExConstants.ds");
// Sample Logging ImportScript
importScript("bc_sample:library/common/libContext.ds");
importScript("bc_sample:library/utility/exception/libsampleException.ds");
importScript("bc_sample:library/utility/logging/libLog.ds");



function execute(pdict: PipelineDictionary): Number {
    // Sample Logging var
    var _context: String = new Context("RenameFile.ds");
    var _logger: Log = Log.getLogger(pdict);



    var sourceFileName: String = pdict.SourceFileName;
    var targetFileName: String = pdict.TargetFileName;
    var sourceDirectory: String = pdict.SourceDirectory;
    var targetDirectory: String = pdict.TargetDirectory;
    var status: String = pdict.Status;

    var sourceFile: File = new File(sourceDirectory, sourceFileName);
    var targetFile: File = new File(targetDirectory, targetFileName);

    if (status != null) {
        _logger.error(_context, "Status :" + status.message + " : End Status");
    }


    if (!sourceFile.exists()) {
        _logger.error(_context, "Source file '" + sourceFile.name + "' in path '" + sourceFile.path + "' cannot be found");
        return PIPELET_ERROR;
    }
    if (targetFile.exists()) {
        _logger.warn(_context, "Target file '" + targetFile.name + "' in path '" + targetFile.path + "' already exists. Overwriting it.");
    }

    _logger.info(_context, "Moving file " + sourceFile.name + " to " + targetFile.name);

    try {
        sourceFile.renameTo(targetFile);
        pdict.TargetFile = targetFile;



    } catch (e) {
        var exception: sampleException = new sampleException(_context, "Failed moving file " + sourceFileName, e);
        _logger.error(_context, "Failed moving file " + sourceFileName + exception);
        pdict.sampleError = exception;

        return PIPELET_ERROR;
    }

    return PIPELET_NEXT;
}
```
