Add detailed logging to file moving functionality for debugging
This commit is contained in:
parent
9f8f428da4
commit
83a5a734b8
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
|
// IPC handler for moving file to folder
|
||||||
ipcMain.handle('move-file-to-folder', async (event, { filePath, folderName }) => {
|
ipcMain.handle('move-file-to-folder', async (event, { filePath, folderName }) => {
|
||||||
try {
|
try {
|
||||||
|
console.log('Move file request received:', { filePath, folderName });
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
// Check if file exists
|
// Check if file exists
|
||||||
if (!fs.existsSync(filePath)) {
|
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
|
// Validate folder name
|
||||||
if (folderName !== 'extra' && folderName !== 'commentary') {
|
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
|
// Get directory containing the file
|
||||||
const fileDir = path.dirname(filePath);
|
const fileDir = path.dirname(filePath);
|
||||||
const targetFolder = path.join(fileDir, folderName);
|
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
|
// Create the target folder if it doesn't exist
|
||||||
if (!fs.existsSync(targetFolder)) {
|
if (!fs.existsSync(targetFolder)) {
|
||||||
|
console.log('Creating target folder:', targetFolder);
|
||||||
fs.mkdirSync(targetFolder, { recursive: true });
|
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 fileName = path.basename(filePath);
|
||||||
const newFilePath = path.join(targetFolder, fileName);
|
const newFilePath = path.join(targetFolder, fileName);
|
||||||
|
|
||||||
|
console.log('New file path:', newFilePath);
|
||||||
|
|
||||||
// Check if file with same name already exists in target folder
|
// Check if file with same name already exists in target folder
|
||||||
if (fs.existsSync(newFilePath)) {
|
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
|
// Move the file
|
||||||
|
console.log('Moving file...');
|
||||||
fs.renameSync(filePath, newFilePath);
|
fs.renameSync(filePath, newFilePath);
|
||||||
|
|
||||||
|
console.log('File moved successfully to:', newFilePath);
|
||||||
return { success: true, message: `File moved to ${folderName} folder successfully` };
|
return { success: true, message: `File moved to ${folderName} folder successfully` };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Error in move-file-to-folder:', error);
|
||||||
return { success: false, error: error.message };
|
return { success: false, error: error.message };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user