From 83a5a734b8e6b862bc1909b4bc067f33f86318b5 Mon Sep 17 00:00:00 2001 From: Jarian Cottingham Date: Sat, 21 Feb 2026 15:51:42 -0600 Subject: [PATCH] Add detailed logging to file moving functionality for debugging --- main.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 86405c9..9b81f53 100644 --- a/main.js +++ b/main.js @@ -121,25 +121,35 @@ ipcMain.handle('rename-file', async (event, { oldPath, newName }) => { // IPC handler for moving file to folder ipcMain.handle('move-file-to-folder', async (event, { filePath, folderName }) => { try { + console.log('Move file request received:', { filePath, folderName }); + const fs = require('fs'); const path = require('path'); // Check if file exists if (!fs.existsSync(filePath)) { - return { success: false, error: 'File does not exist' }; + const error = 'File does not exist'; + console.error(error); + return { success: false, error: error }; } // Validate folder name if (folderName !== 'extra' && folderName !== 'commentary') { - return { success: false, error: 'Invalid folder name. Must be "extra" or "commentary"' }; + const error = 'Invalid folder name. Must be "extra" or "commentary"'; + console.error(error); + return { success: false, error: error }; } // Get directory containing the file const fileDir = path.dirname(filePath); const targetFolder = path.join(fileDir, folderName); + console.log('Moving file from:', filePath); + console.log('Target folder:', targetFolder); + // Create the target folder if it doesn't exist if (!fs.existsSync(targetFolder)) { + console.log('Creating target folder:', targetFolder); fs.mkdirSync(targetFolder, { recursive: true }); } @@ -147,16 +157,23 @@ ipcMain.handle('move-file-to-folder', async (event, { filePath, folderName }) => const fileName = path.basename(filePath); const newFilePath = path.join(targetFolder, fileName); + console.log('New file path:', newFilePath); + // Check if file with same name already exists in target folder if (fs.existsSync(newFilePath)) { - return { success: false, error: 'File with same name already exists in target folder' }; + const error = 'File with same name already exists in target folder'; + console.error(error); + return { success: false, error: error }; } // Move the file + console.log('Moving file...'); fs.renameSync(filePath, newFilePath); + console.log('File moved successfully to:', newFilePath); return { success: true, message: `File moved to ${folderName} folder successfully` }; } catch (error) { + console.error('Error in move-file-to-folder:', error); return { success: false, error: error.message }; } });