Pages

Se afișează postările cu eticheta google. Afișați toate postările
Se afișează postările cu eticheta google. Afișați toate postările

marți, 25 martie 2025

News : Google Apps Script - find duplicate files in google drive.

For today, a simple GAScript source code to add into spreadsheet the duplicate files from Google drive.
This Google Apps Script finds duplicate files in Google Drive by comparing file sizes and optionally file types. It then displays the results in a spreadsheet with detailed information about each duplicate file. The script collects information about all files in Drive. Files are grouped by their size and optionally file type. Any group with more than one file is considered a set of duplicates These duplicate sets are displayed in the spreadsheet
Functions
  • checkDuplicatesInDrive(): Main function that searches your entire Google Drive for duplicates
  • checkDuplicatesInFolder(): Alternative function that searches a specific folder and its subfolders
  • findDuplicateFiles(): Core function that identifies duplicate files based on size and type
  • addDuplicatesToSheet(): Adds the found duplicates to a spreadsheet
I used artificial inteligence and this help me much ...
/**
 * Main function to check files in the root folder and add duplicates to the active spreadsheet
 */
function checkDuplicatesInDrive() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  
  // Clear the sheet and set up headers
  sheet.clear();
  sheet.appendRow(["Group", "File Name", "Size", "Type", "File Path", "Date Created", "Last Updated", "URL"]);
  sheet.getRange(1, 1, 1, 8).setFontWeight("bold").setBackground("#f3f3f3");
  
  // Find all duplicates
  const duplicates = findDuplicateFiles(true);
  
  // Check if any duplicates were found
  if (Object.keys(duplicates).length === 0) {
    sheet.appendRow(["No duplicate files found"]);
    sheet.autoResizeColumns(1, 8);
    return;
  }
  
  // Add duplicates to the sheet
  addDuplicatesToSheet(duplicates, sheet);
  
  // Auto-resize columns
  sheet.autoResizeColumns(1, 8);
}

/**
 * Adds duplicate files to the specified sheet
 */
function addDuplicatesToSheet(duplicates, sheet) {
  let groupNumber = 1;
  let rowIndex = 2;
  let totalDuplicateFiles = 0;
  
  for (const key in duplicates) {
    const files = duplicates[key];
    totalDuplicateFiles += files.length;
    
    files.forEach((file, index) => {
      // Get file path
      const filePath = getFilePath(file.id);
      
      sheet.appendRow([
        groupNumber,
        file.name,
        formatFileSize(file.size),
        file.mimeType,
        filePath,
        file.dateCreated.toLocaleString(),
        file.lastUpdated.toLocaleString(),
        file.url
      ]);
      
      // Add hyperlink to the file URL
      sheet.getRange(rowIndex, 8).setFormula(`=HYPERLINK("${file.url}","Open File")`);
      
      rowIndex++;
    });
    
    groupNumber++;
  }
  
  // Add summary at the bottom - only if we have duplicates
  if (totalDuplicateFiles > 0) {
    sheet.appendRow(["SUMMARY"]);
    sheet.appendRow([`Found ${totalDuplicateFiles} duplicate files in ${groupNumber - 1} groups.`]);
  }
  
  return totalDuplicateFiles;
}

/**
 * Gets the file path for a given file ID
 */
function getFilePath(fileId) {
  try {
    const file = DriveApp.getFileById(fileId);
    const parents = file.getParents();
    
    if (parents.hasNext()) {
      const parent = parents.next();
      return getFolderPath(parent) + "/" + file.getName();
    } else {
      return "/" + file.getName();
    }
  } catch (e) {
    return "Path not available";
  }
}

/**
 * Gets the folder path for a given folder
 */
function getFolderPath(folder) {
  try {
    const parents = folder.getParents();
    
    if (!parents.hasNext()) {
      return "/" + folder.getName();
    }
    
    const parent = parents.next();
    return getFolderPath(parent) + "/" + folder.getName();
  } catch (e) {
    return "/Unknown";
  }
}

/**
 * Finds duplicate files in Google Drive based on file size and optionally file type.
 * @param {boolean} considerFileType Whether to consider file type when finding duplicates (default: true)
 * @param {string} folderId Optional folder ID to search in. If not provided, searches in the entire Drive.
 * @return {Object} An object containing groups of duplicate files
 */
function findDuplicateFiles(considerFileType = true, folderId = null) {
  // Create a map to store files by their size (and optionally type)
  const fileMap = {};
  
  // Get files to check
  let files;
  if (folderId) {
    const folder = DriveApp.getFolderById(folderId);
    files = folder.getFiles();
  } else {
    files = DriveApp.getFiles();
  }
  
  // Process each file
  while (files.hasNext()) {
    const file = files.next();
    // Skip Google Docs, Sheets, etc. as they don't have a fixed size
    if (file.getSize() === 0) continue;
    
    const fileSize = file.getSize();
    const mimeType = file.getMimeType();
    
    // Create a key based on file size and optionally type
    let key = fileSize.toString();
    if (considerFileType) {
      key += '_' + mimeType;
    }
    
    // Add file to the map
    if (!fileMap[key]) {
      fileMap[key] = [];
    }
    
    fileMap[key].push({
      id: file.getId(),
      name: file.getName(),
      size: fileSize,
      mimeType: mimeType,
      url: file.getUrl(),
      dateCreated: file.getDateCreated(),
      lastUpdated: file.getLastUpdated()
    });
  }
  
  // Filter out unique files (groups with only one file)
  const duplicates = {};
  for (const key in fileMap) {
    if (fileMap[key].length > 1) {
      duplicates[key] = fileMap[key];
    }
  }
  
  return duplicates;
}

/**
 * Alternative function to check files in a specific folder and its subfolders
 */
function checkDuplicatesInFolder() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  
  // Clear the sheet and set up headers
  sheet.clear();
  sheet.appendRow(["Group", "File Name", "Size", "Type", "File Path", "Date Created", "Last Updated", "URL"]);
  sheet.getRange(1, 1, 1, 8).setFontWeight("bold").setBackground("#f3f3f3");
  
  // Collect all files from the folder and subfolders
  var fileMap = {};
  var rootFolder = DriveApp.getRootFolder(); // Change this to your specific folder if needed
  collectFilesFromFolder(rootFolder, fileMap);
  
  // Filter out unique files
  const duplicates = {};
  for (const key in fileMap) {
    if (fileMap[key].length > 1) {
      duplicates[key] = fileMap[key];
    }
  }
  
  // Check if any duplicates were found
  if (Object.keys(duplicates).length === 0) {
    sheet.appendRow(["No duplicate files found"]);
    sheet.autoResizeColumns(1, 8);
    return;
  }
  
  // Add duplicates to the sheet
  addDuplicatesToSheet(duplicates, sheet);
  
  // Auto-resize columns
  sheet.autoResizeColumns(1, 8);
}

/**
 * Recursively collects files from a folder and its subfolders
 */
function collectFilesFromFolder(folder, fileMap, considerFileType = true) {
  // Process files in this folder
  var files = folder.getFiles();
  while (files.hasNext()) {
    const file = files.next();
    // Skip Google Docs, Sheets, etc. as they don't have a fixed size
    if (file.getSize() === 0) continue;
    
    const fileSize = file.getSize();
    const mimeType = file.getMimeType();
    
    // Create a key based on file size and optionally type
    let key = fileSize.toString();
    if (considerFileType) {
      key += '_' + mimeType;
    }
    
    // Add file to the map
    if (!fileMap[key]) {
      fileMap[key] = [];
    }
    
    fileMap[key].push({
      id: file.getId(),
      name: file.getName(),
      size: fileSize,
      mimeType: mimeType,
      url: file.getUrl(),
      dateCreated: file.getDateCreated(),
      lastUpdated: file.getLastUpdated()
    });
  }
  
  // Process subfolders
  var subfolders = folder.getFolders();
  while (subfolders.hasNext()) {
    var subfolder = subfolders.next();
    collectFilesFromFolder(subfolder, fileMap, considerFileType);
  }
}

/**
 * Helper function to format file size in a human-readable format
 */
function formatFileSize(bytes) {
  if (bytes < 1024) return bytes + " bytes";
  else if (bytes < 1048576) return (bytes / 1024).toFixed(2) + " KB";
  else if (bytes < 1073741824) return (bytes / 1048576).toFixed(2) + " MB";
  else return (bytes / 1073741824).toFixed(2) + " GB";
}

/**
 * Creates a new Google Spreadsheet with the duplicate files report
 */
function createDuplicateFilesSpreadsheet() {
  const duplicates = findDuplicateFiles(true);
  
  // Create a new spreadsheet
  const ss = SpreadsheetApp.create("Duplicate Files Report - " + new Date().toLocaleString());
  const sheet = ss.getActiveSheet();
  
  // Set up headers
  sheet.appendRow(["Group", "File Name", "Size", "Type", "File Path", "Date Created", "Last Updated", "URL"]);
  
  // Format header row
  sheet.getRange(1, 1, 1, 8).setFontWeight("bold").setBackground("#f3f3f3");
  
  // Check if any duplicates were found
  if (Object.keys(duplicates).length === 0) {
    sheet.appendRow(["No duplicate files found"]);
    sheet.autoResizeColumns(1, 8);
    return ss.getUrl();
  }
  
  // Add duplicates to the sheet
  addDuplicatesToSheet(duplicates, sheet);
  
  // Auto-resize columns
  sheet.autoResizeColumns(1, 8);
  
  Logger.log(`Spreadsheet created: ${ss.getUrl()}`);
  return ss.getUrl();
}
See the result into the spreadsheet:

vineri, 21 martie 2025

News : CLASP 3.0 Alpha google script.

CLASP (Command Line Apps Script Projects) is a tool developed by Google that allows developers to manage and develop Google Apps Script projects using a terminal instead of the standard browser editor. It simplifies workflows and supports modern project structures.
  • Key features include:
  • Import/Export: Clone and sync script projects between your terminal and Google account.
  • Version Management: Create, publish, and update script versions.
  • TypeScript Support: Write structured and robust code.
  • Google Workspace Integration: Deploy scripts for automating Workspace processes.

vineri, 22 noiembrie 2024

News : Project IDX from google.

I wrote about this project, and today I test this online tool and works great.
Project IDX is an online integrated development environment (IDE) developed by Google. It is based on Visual Studio Code, and the infrastructure runs on Google Cloud. In addition to including the features, languages and plugins supported by VS Code, it has unique functionality built by Google.
Test this online tool on the official webpage.

sâmbătă, 19 octombrie 2024

News : the Google Research with AI Colab and more ...

I saw few days ago the new AI implementation from Google Colab and I found the Google Research ...
This AI seams to work with development task, not all AI for development works well ...

marți, 10 septembrie 2024

News : Looker Studio and google sheet.

The Looker Studio can be found now on google sheet menu on Extension item.
I think the Looker Studio feature start few years ago ...

marți, 19 decembrie 2023

News : Google new online game .

Look for 25 of the most-searched people, places and things of all time, hidden in our Most Searched Playground. Play now.
The idea is to Uncover 25 of the most searched people, places, and moments from the past 25 years.

joi, 14 decembrie 2023

News : Google trending in 2023.

I was born in Romania, and I will stay here for a long time, especially in Falticeni when I arrived a few years ago.
See what was trending in 2023 - in my country Romania:
  • The times of the year
  • Cutremur
  • Chat GPT
  • Rona Hartner
  • Israel Gaza conflict
  • Iphone 15

sâmbătă, 9 decembrie 2023

News : Changes in Google BARD.

You can test BARD on the official google webpage.
This is a short video from google youtube official channel.
Last news:
2023.11.21
Expanding Bard’s understanding of YouTube videos
What: We're taking the first steps in Bard's ability to understand YouTube videos. For example, if you’re looking for videos on how to make olive oil cake, you can now also ask how many eggs the recipe in the first video requires.
Why: We’ve heard you want deeper engagement with YouTube videos. So we’re expanding the YouTube Extension to understand some video content so you can have a richer conversation with Bard about it.

sâmbătă, 2 decembrie 2023

News : Chart with sizes values from Google Drive.

Visual data representation in graphical format can solve many of today's issues.
Here is a tutorial with a Google Apps Script script that allows you to view the size of the files in Google Drive in Chart Pie format and modify it.
You can find more tutorials about Google Apps Script on my Google site.
Let's see the source code:
function generateDriveUsageReportPie() {
  var drive = DriveApp.getRootFolder();
  var files = drive.getFiles();

  var data = [['Nume Fișier', 'Dimensiune (KB)']];
  
  while (files.hasNext()) {
    var file = files.next();
    var fileSizeBytes = file.getSize();
    var fileSizeKB = fileSizeBytes / 1024; // Convertim dimensiunea în KB
    data.push([file.getName(), fileSizeKB]);
  }

  // open Google Sheet
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName('Drive Usage Report');
  if (!sheet) {
    sheet = spreadsheet.insertSheet('Drive Usage Report');
  }

  // clean sheet
  sheet.clear();

  // write values
  sheet.getRange(1, 1, data.length, data[0].length).setValues(data);

  // clean charts from Google Sheets
  var charts = sheet.getCharts();
  for (var i = 0; i < charts.length; i++) {
    sheet.removeChart(charts[i]);
  }

  // create and add the Pie Chart with all values
  var chart = sheet.newChart()
    .asPieChart()
    .setTitle('Utilizare Google Drive')
    .addRange(sheet.getRange(2, 1, data.length - 1, 2))  // Exclude header row
    .setPosition(5, 1, 0, 0)
    .setOption('title', 'Utilizare Google Drive')
    .setOption('legend', {position: 'top'})
    .build();

  sheet.insertChart(chart);

  Logger.log('Raport generat cu succes.');
}
Here is the result obtained:

sâmbătă, 11 noiembrie 2023

News : Google adsense and GDPR.

It is obvious that human interface and design are closely related. The law obliges us to a specific design for displaying Google ads.
Beginning January 16, 2024, Google will require all publishers serving ads to EEA and UK users to use a Google-certified Consent Management Platform (CMP). You can use any Google-certified CMP for this purpose, including Google's own consent management solution. If you are interested in using Google's consent management solution, start by setting up your GDPR message.
This message indicates that your website currently lacks a Google-certified Consent Management Platform (CMP) for GDPR (General Data Protection Regulation). As a result, your sites will cease to display AdSense ads and receive AdSense revenue for traffic from the European Economic Area (EEA) and the United Kingdom (UK) in accordance with Google's EU user consent policy.
Using the second option from google settings will set GDPR message by goodle adsense ...
Use Google's CMP in AdSense: If you prefer, you can use the CMP provided by Google directly in AdSense to create your GDPR message. Like the first option, this will help you remain GDPR compliant.
You can see in the next image how the message that will be the protagonist of this new implementation will look like:

luni, 28 august 2023

News : Gogle comes with Project IDX.

Google comes with idx.dev.
Project IDX starts with a web-based workspace that'll feel familiar for coding but fresh. And we're just at the beginning of this journey. We'd love your input as we work to make application development better.
Project IDX makes it easier to start building an app that works across multiple platforms using a variety of templates for popular frameworks, such as Angular, Next.js, React, Svelte, and Flutter, with Python and Go support coming soon. You can also import your existing applications from GitHub, with support for most tech stacks.

miercuri, 12 iulie 2023

News : ... the new GMail design from Google.

Take your email game to the next level! With mail merge through Google Sheets and custom layouts in Gmail, you can easily personalize your messages and make a lasting impression ...

luni, 15 august 2022

Shader Editor mobile application.

This android application from google play lets you create shaders and use them like wallpapers for your phone.
The application is named Shader Editor and can be found on the Google Play website.

marți, 3 mai 2022

News : Geographical-Adventures game.

A little work-in-progress geography game about delivering packages to different countries around the world.
This intro come from the GitHub project page.
Today the author of this project build with Unity game engine come with new video:

vineri, 29 aprilie 2022

News : Noto emoji ...

In 1999 — back when Snake 🐍 was the best thing about your phone 📱 — there were three phone carriers in Japan 🗾 . On these phones were tiny, beautiful pictures called emoji (meaning “picture” and “character” in Japanese 🥰). These 176 images were very simple — think 8-bit tech — and as a result were exquisitely abstract and tremendously useful when texting ✨ Twenty years later 👶🕛🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🧓, emoji are a global phenomenon 🌎. Now, our phones have fancy retina screens and somewhere along the way an important part of what made emoji so handy was left by the wayside: their simplicity. That’s why we’ve created a new emoji font: a monochrome Noto Emoji (a black and white companion to Noto Emoji Color).
See this article on the google webpage.

sâmbătă, 31 iulie 2021

News : Poly was shut down ...

Poly was shut down on June 30, 2021. What does this mean for you? The ability to download assets was disabled on June 30, 2021. The ability to upload new 3D models on poly.google.com was disabled on April 30, 2021.
See the official website from Google.

sâmbătă, 26 iunie 2021

News : $140,000 USD in prizes by Core Games.

Enter the Core Invitational game dev competition from July 29 to August 30 with $140,000 USD in prizes, including a grand prize Tesla Model 3! Visit https://invitational.coregames.com to download and create for free today!
Core is the easiest way to build, host, and run multiplayer games and worlds.
This team provide all you need to build a game from assets, servers, and all the code needed to get your first game built and published in minutes.
You can see more on the youtube official channel.

joi, 24 iunie 2021

News : Paint With Music from Google Arts & Culture.

What if you can hear your painting? Turn your paint brush into musical instruments and compose on sensorial canvases!
, see this online tool here.
The Google Arts & Culture is a non-profit initiative with cultural institutions and artists around the world.

sâmbătă, 28 martie 2020

Firebase and Unity 3D.

Even is an old feature the Google team comes with this new option for the new developers and show how to use them.
The goal is to add Firebase to your Unity project.
The Google webpage tells us:
Power up your Unity games with our Firebase Unity SDKs. To show how easy it is to plug Firebase into your Unity project, we made a sample game, MechaHamster, that you can download from GitHub, the App Store, and the Google Play Store.
... and show a short video about how can be used to create a application named Mecha Hamster, see the GitHub webpage project:
You can import the project with GitHub commands:
https://github.com/google/mechahamster.git
...
The game is pretty funny, see the Youtube channel from Firebase:

The content of the folder downloaded ...
$ ls
Assets   CONTRIBUTING.txt  LICENSE.txt      readme.md  UnityPackageManager
console  docs              ProjectSettings  Resources