'How do I delete subfolders with the same name under multiple directories in Windows?
I have a folder tree similar to this:
main_folder\folder1\Debug\(file1.a1, file2.a2, file3.a3 ...)
main_folder\folder2\Debug\(file1.a1, file2.a2, file3.a3 ...)
main_folder\folder3\Debug\(file1.a1, file2.a2, file3.a3 ...)
folder1, 2, 3 contain many other files and folders besides Debug. Debug subfolder is not empty in any of the folders. I want to delete the Debug subfolder (and everything in it) from all folders 1, 2, 3. How do I delete the Debug subfolder in all these folders using a bat script?
Solution 1:[1]
UNTESTED It loop thropugh main_folder, read names of its subdirs than delete Debug subfolder of each main_folder subfolder, including its content.
for /f "tokens=3 delims=\" %%a in ('dir /b /s /a:d "main_folder"') do rd /S main_folder\%%a\Debug
Solution 2:[2]
Since you've mentioned that I need to make it so the bedtimes and get up times only alternate if there is a difference between the previous date and the current date, I'm using the hidden A column to store dates as key of this data set.
Just keep in mind that if in your use case you can have multiple bedtimes on the same day, you will need to change this implementation.
Additionally, it is not possible to "freeze" a Drawing object to a cell in Sheets unfortunately. If you want to workaround that, consider rendering your own sidebar using HTML or even adding a custom top menu item
See my implementation below:
Sample Code:
function setValue(cellName, value) {
SpreadsheetApp.getActiveSpreadsheet().getRange(cellName).setValue(value);
}
function getValue(cellName) {
return SpreadsheetApp.getActiveSpreadsheet().getRange(cellName).getValue();
}
function getTodayRowNumber() {
var todayRow = findTodayRow(); // Find/create Today's row
return todayRow.getRowIndex(); // Return Today's row index
}
function addBedTime(a) {
//let row = 2
var row = getTodayRowNumber();
if (getValue('b' + row) == '') {
setValue('b' + row, a);
//row += 1
}
}
function addGetUpTime(a) {
//Assuming the get up time is always entryDate+1, then
//Get Up time should check if last entry is blank
//If true, add Get Up Time on the last entry row
//Otherwise, insert your logic for this scenario
var row = getTodayRowNumber() - 1; //Get previous entry row number
row = (row > 1) ? row : 2; //Bug fix in case there is only headers in the sheet
if (getValue('e' + row) == '') { //only change column E if it is blank
setValue('e' + row, a)
//row +=1
}
}
function punchIn() {
addBedTime(new Date());
}
function punchOut() {
addGetUpTime(new Date());
}
function findTodayRow(){
var ss = SpreadsheetApp.getActiveSpreadsheet(); //Initiating opened Spreadsheet
var ws = ss.getActiveSheet(); //Getting active Worksheet in opened Spreadsheet
var dataRange = ws.getDataRange(); //Getting used range of cells
var lastLoggedDay = dataRange.getCell(dataRange.getLastRow(), 1).getValue(); //getting last A column from used range
lastLoggedDay = (lastLoggedDay) ? lastLoggedDay : (new Date(0)); //Fixing scenario where Column A is blank
lastLoggedDay.setHours(0,0,0,0); //clearing time for later date comparison
var today = (new Date()); //getting today's date
today.setHours(0,0,0,0); //clearing time for later date comparison
if(today.getTime() == lastLoggedDay.getTime()){
//if the last logged day is same as today, then return the Row Range for today
return ws.getRange("A" + String(dataRange.getLastRow()) + ":" + String(dataRange.getLastRow()));
} else {
//if the last logged day is NOT the same as today,
//then "create" a new row and
//put today's date in hidden Column A,
//then return the newly created Row Range for today
var newRow = ws.getRange("A" + String(dataRange.getLastRow()+1) + ":" + String(dataRange.getLastRow()+1));
newRow.getCell(1, 1).setValue(today); //getting first cell of today's range (should be hidden Date column)
return newRow;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user2956477 |
| Solution 2 |
