Hi team,
I want to upload the files to the specific folder using Python code in UiPath.
Can anyone please help me with this? I have zero knowledge of this topic.
Thanks,
Chethan P
Hi team,
I want to upload the files to the specific folder using Python code in UiPath.
Can anyone please help me with this? I have zero knowledge of this topic.
Thanks,
Chethan P
source_folder = r’C:\path\to\source\folder’
destination_folder = r’C:\path\to\destination\folder’
-Get the list of files in the source folder
files_to_upload = os.listdir(source_folder)
-Upload each file to the destination folder
for file_name in files_to_upload:
source_path = os.path.join(source_folder, file_name)
destination_path = os.path.join(destination_folder, file_name)
shutil.copy2(source_path, destination_path)
The below Code work
import os
import shutil
def move_files(source_path, destination_path):
try:
# Check if the source directory exists
if not os.path.exists(source_path):
return "Source directory does not exist"
# List all files in the source directory
files = os.listdir(source_path)
# Filter files with specified extensions
valid_files = [file for file in files if file.lower().endswith(('.pdf', '.png', '.jpg', '.jpeg'))]
# Check if there are no valid files in the source directory
if not valid_files:
return "No valid files are present in the source folder"
# Check if the destination directory exists, create if not
if not os.path.exists(destination_path):
os.makedirs(destination_path)
# Move PDF and image files to the destination directory
for file in valid_files:
source_file_path = os.path.join(source_path, file)
destination_file_path = os.path.join(destination_path, file)
shutil.move(source_file_path, destination_file_path)
return "File Move success"
except Exception as e:
return f"Error: {str(e)}"
source_path = r'source_path'
destination_path = r'destination_path'
# Example usage
#source_path = r'C:\Users\admin\Desktop\Document UnderStanding input\Source folder'
#estination_path = r'C:\Users\admin\Documents\UiPath\Document Understanding\Destination Folder'
result = move_files(source_path, destination_path)
# Additional condition to check if no files were moved
if "No valid files" in result and "File Move success" not in result:
print("No files are available to move.")
else:
print(result)
Steps need to follow for the first time:
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.