Add detailed logging to file moving functionality for debugging
This commit is contained in:
parent
3794289de5
commit
51ffed0d2d
23
main.js
23
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 };
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user