Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Move files without using Run Command tool

binay2448
11 - Bolide

Please suggest how can we move files in different folder without using Run Command tool. 

We need to move file from a folder to Archive folder after processing.   

5 REPLIES 5
messi007
15 - Aurora
15 - Aurora

@binay2448,

 

You can move files with blob tools.

Please see below,

I add a comment on the workflow to explain the steps,

messi007_0-1633600529026.png

 

Attached the workflow,

 

Regards,

Prime.PNG

 

binay2448
11 - Bolide

Hi @messi007,

 

I want to move the files from source folder to destination folder. your workflow copy files from source folder and pasting it to destination folder. Not deleting it form the source folder. 

 

messi007
15 - Aurora
15 - Aurora

@binay2448,

 

As my knowledge you can't do this without cmd.

 

Regards,

Pawel_Lula
5 - Atom

You can do move/"cut and paste" using Python script.

 

#################################
import os
import shutil
from glob import iglob


#################################
def move_all_latest_files(source_dir, destination_dir):
files = os.listdir(source_dir)

if not files:
print(f"No files found in {source_dir}. Skipping processing.")
return
'''
for filename in files:
source_file = os.path.join(source_dir, filename)
destination_file = os.path.join(destination_dir, filename)
shutil.move(source_file, destination_file)
'''
for root, directories, files in os.walk(source_dir):
for filename in files:
source_file = os.path.join(root, filename)
destination_file = os.path.join(destination_dir, os.path.relpath(source_file, source_dir))
shutil.move(source_file, destination_file)
print(f"Moved all files from {source_dir} to {destination_dir}")


#################################
source_dir = r'\\Your_Source_Path'
destination_dir = r'\\Destination_Path'

move_all_latest_files(source_dir, destination_dir)

rdlalli
6 - Meteoroid

I found this to work very well.  I have a couple of additional notes.

  • I used os.listdir() to directly list files in source_dir without using os.walk(), thus avoiding interaction with subdirectories.
  • for the source_dir and destination_dir, I found it better to use the UNC path rather than the drive-letter path as  raw strings (e.g., r'P:\...) for the directories.  Raw strings may be optimal for paths containing backslashes in Python. However, consider switching to UNC paths if there's a chance of drive mapping inconsistencies.

Finally, I added this small bit because I was only interested in Excel file types.

 

for filename in files:

# Check if the file is an Excel file

if filename.endswith(('.xlsx', '.xls', '.xlsm')):

source_file = os.path.join(source_dir, filename)

destination_file = os.path.join(destination_dir, filename)

Labels
Top Solution Authors