Removing old folders and keeping the most recent
I have been working on a script of late and have come across a snag. I am in the process of removing folders which are automatically created. I want to delete the older versions of those files whilst keeping the new folders untouched, for example:
- 18.212.1021.0008 //Created on the 19/11/2018 12:12
- 18.212.1021.0008_1 //Created on the 19/11/2018 12:23
- 18.212.1021.0008_2 //Created on the 19/11/2018 12:27
- 18.212.1021.0008_3 //Created on the 19/11/2018 12:32
I would want to keep 18.212.1021.008_3 so I guess I would need to keep the folder with the most recent creation date.
Please see the code below:
$Versionarray = 13..20
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Recurse | Where-Object {
# Recusivly deletes OneDrive version folders within
# Appdatalocal which build up everytime OneDrive
# is installed/script is run
$item = $_
$item -is [System.IO.DirectoryInfo] -and (
$Versionarray | Where-Object { $item.Name.Contains($_) }
)
} | Remove-Item -Recurse -Confirm:$false -ErrorAction SilentlyContinue
powershell folder
add a comment |
I have been working on a script of late and have come across a snag. I am in the process of removing folders which are automatically created. I want to delete the older versions of those files whilst keeping the new folders untouched, for example:
- 18.212.1021.0008 //Created on the 19/11/2018 12:12
- 18.212.1021.0008_1 //Created on the 19/11/2018 12:23
- 18.212.1021.0008_2 //Created on the 19/11/2018 12:27
- 18.212.1021.0008_3 //Created on the 19/11/2018 12:32
I would want to keep 18.212.1021.008_3 so I guess I would need to keep the folder with the most recent creation date.
Please see the code below:
$Versionarray = 13..20
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Recurse | Where-Object {
# Recusivly deletes OneDrive version folders within
# Appdatalocal which build up everytime OneDrive
# is installed/script is run
$item = $_
$item -is [System.IO.DirectoryInfo] -and (
$Versionarray | Where-Object { $item.Name.Contains($_) }
)
} | Remove-Item -Recurse -Confirm:$false -ErrorAction SilentlyContinue
powershell folder
The sample code you posted is broken. Please create a Minimal, Complete, and Verifiable example, then edit your question and post that code along with all errors that code throws. Also, do the names all folders you want processed have the same format? Like, some text optionally followed by an underscore and a number?
– Ansgar Wiechers
Nov 19 '18 at 12:53
Apologies, I have removed the curly bracket below it. This should now work. If the folder is locked by the system you might see a few errors but this would be the folder I would want to avoid and keep.
– Marshal
Nov 19 '18 at 13:00
Please also answer the question from my previous comment.
– Ansgar Wiechers
Nov 19 '18 at 13:05
@AnsgarWiechers Your question is an interesting on. Sooo, the folder is randomly generated. The folder relates to the version so if the folder name for the original version is free then OneDrive will use that. If it's not then it will add an underscore and increment the number. This means that if you have 18.212.1021.0008, 18.212.1021.0008_1, 18.212.1021.0008_2 and delete "18.212.1021.0008" then the next time OneDrive re-creates the folder it will use 18.212.1021.0008. Hence why I want the others removed to stop the folder getting bunged up with lots of folders.
– Marshal
Nov 19 '18 at 13:14
add a comment |
I have been working on a script of late and have come across a snag. I am in the process of removing folders which are automatically created. I want to delete the older versions of those files whilst keeping the new folders untouched, for example:
- 18.212.1021.0008 //Created on the 19/11/2018 12:12
- 18.212.1021.0008_1 //Created on the 19/11/2018 12:23
- 18.212.1021.0008_2 //Created on the 19/11/2018 12:27
- 18.212.1021.0008_3 //Created on the 19/11/2018 12:32
I would want to keep 18.212.1021.008_3 so I guess I would need to keep the folder with the most recent creation date.
Please see the code below:
$Versionarray = 13..20
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Recurse | Where-Object {
# Recusivly deletes OneDrive version folders within
# Appdatalocal which build up everytime OneDrive
# is installed/script is run
$item = $_
$item -is [System.IO.DirectoryInfo] -and (
$Versionarray | Where-Object { $item.Name.Contains($_) }
)
} | Remove-Item -Recurse -Confirm:$false -ErrorAction SilentlyContinue
powershell folder
I have been working on a script of late and have come across a snag. I am in the process of removing folders which are automatically created. I want to delete the older versions of those files whilst keeping the new folders untouched, for example:
- 18.212.1021.0008 //Created on the 19/11/2018 12:12
- 18.212.1021.0008_1 //Created on the 19/11/2018 12:23
- 18.212.1021.0008_2 //Created on the 19/11/2018 12:27
- 18.212.1021.0008_3 //Created on the 19/11/2018 12:32
I would want to keep 18.212.1021.008_3 so I guess I would need to keep the folder with the most recent creation date.
Please see the code below:
$Versionarray = 13..20
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Recurse | Where-Object {
# Recusivly deletes OneDrive version folders within
# Appdatalocal which build up everytime OneDrive
# is installed/script is run
$item = $_
$item -is [System.IO.DirectoryInfo] -and (
$Versionarray | Where-Object { $item.Name.Contains($_) }
)
} | Remove-Item -Recurse -Confirm:$false -ErrorAction SilentlyContinue
powershell folder
powershell folder
edited Nov 19 '18 at 13:01
marsze
4,60031740
4,60031740
asked Nov 19 '18 at 12:39
MarshalMarshal
54731527
54731527
The sample code you posted is broken. Please create a Minimal, Complete, and Verifiable example, then edit your question and post that code along with all errors that code throws. Also, do the names all folders you want processed have the same format? Like, some text optionally followed by an underscore and a number?
– Ansgar Wiechers
Nov 19 '18 at 12:53
Apologies, I have removed the curly bracket below it. This should now work. If the folder is locked by the system you might see a few errors but this would be the folder I would want to avoid and keep.
– Marshal
Nov 19 '18 at 13:00
Please also answer the question from my previous comment.
– Ansgar Wiechers
Nov 19 '18 at 13:05
@AnsgarWiechers Your question is an interesting on. Sooo, the folder is randomly generated. The folder relates to the version so if the folder name for the original version is free then OneDrive will use that. If it's not then it will add an underscore and increment the number. This means that if you have 18.212.1021.0008, 18.212.1021.0008_1, 18.212.1021.0008_2 and delete "18.212.1021.0008" then the next time OneDrive re-creates the folder it will use 18.212.1021.0008. Hence why I want the others removed to stop the folder getting bunged up with lots of folders.
– Marshal
Nov 19 '18 at 13:14
add a comment |
The sample code you posted is broken. Please create a Minimal, Complete, and Verifiable example, then edit your question and post that code along with all errors that code throws. Also, do the names all folders you want processed have the same format? Like, some text optionally followed by an underscore and a number?
– Ansgar Wiechers
Nov 19 '18 at 12:53
Apologies, I have removed the curly bracket below it. This should now work. If the folder is locked by the system you might see a few errors but this would be the folder I would want to avoid and keep.
– Marshal
Nov 19 '18 at 13:00
Please also answer the question from my previous comment.
– Ansgar Wiechers
Nov 19 '18 at 13:05
@AnsgarWiechers Your question is an interesting on. Sooo, the folder is randomly generated. The folder relates to the version so if the folder name for the original version is free then OneDrive will use that. If it's not then it will add an underscore and increment the number. This means that if you have 18.212.1021.0008, 18.212.1021.0008_1, 18.212.1021.0008_2 and delete "18.212.1021.0008" then the next time OneDrive re-creates the folder it will use 18.212.1021.0008. Hence why I want the others removed to stop the folder getting bunged up with lots of folders.
– Marshal
Nov 19 '18 at 13:14
The sample code you posted is broken. Please create a Minimal, Complete, and Verifiable example, then edit your question and post that code along with all errors that code throws. Also, do the names all folders you want processed have the same format? Like, some text optionally followed by an underscore and a number?
– Ansgar Wiechers
Nov 19 '18 at 12:53
The sample code you posted is broken. Please create a Minimal, Complete, and Verifiable example, then edit your question and post that code along with all errors that code throws. Also, do the names all folders you want processed have the same format? Like, some text optionally followed by an underscore and a number?
– Ansgar Wiechers
Nov 19 '18 at 12:53
Apologies, I have removed the curly bracket below it. This should now work. If the folder is locked by the system you might see a few errors but this would be the folder I would want to avoid and keep.
– Marshal
Nov 19 '18 at 13:00
Apologies, I have removed the curly bracket below it. This should now work. If the folder is locked by the system you might see a few errors but this would be the folder I would want to avoid and keep.
– Marshal
Nov 19 '18 at 13:00
Please also answer the question from my previous comment.
– Ansgar Wiechers
Nov 19 '18 at 13:05
Please also answer the question from my previous comment.
– Ansgar Wiechers
Nov 19 '18 at 13:05
@AnsgarWiechers Your question is an interesting on. Sooo, the folder is randomly generated. The folder relates to the version so if the folder name for the original version is free then OneDrive will use that. If it's not then it will add an underscore and increment the number. This means that if you have 18.212.1021.0008, 18.212.1021.0008_1, 18.212.1021.0008_2 and delete "18.212.1021.0008" then the next time OneDrive re-creates the folder it will use 18.212.1021.0008. Hence why I want the others removed to stop the folder getting bunged up with lots of folders.
– Marshal
Nov 19 '18 at 13:14
@AnsgarWiechers Your question is an interesting on. Sooo, the folder is randomly generated. The folder relates to the version so if the folder name for the original version is free then OneDrive will use that. If it's not then it will add an underscore and increment the number. This means that if you have 18.212.1021.0008, 18.212.1021.0008_1, 18.212.1021.0008_2 and delete "18.212.1021.0008" then the next time OneDrive re-creates the folder it will use 18.212.1021.0008. Hence why I want the others removed to stop the folder getting bunged up with lots of folders.
– Marshal
Nov 19 '18 at 13:14
add a comment |
1 Answer
1
active
oldest
votes
If the newest folder you want to keep is also the one with the newest creation time, you can use this simple one-liner:
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Directory | sort CreationTime | select -SkipLast 1 | Remove-Item -Recurse -Force
If you want to filter out only a specific type of folders by name, you could use a simple regex match. I cannot help you with the exact regex (since I would have to know your folder naming pattern) but it would look something like this:
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Directory | where Name -match 'dd+' | sort CreationTime | select -SkipLast 1 | Remove-Item -Recurse -Force
(Note that this is syntax might not work if you use an old Powershell version. If that's the case, let me know and I will provide a compatible fallback solution.)
UPDATE
In response to your comment: Your requirements are still a bit unclear, but here is something to get you started:
If you want to make sure to only delete folders that "look like" version folders, you can adjust the regex in the where-filter. _d+$
will match anything with an underscore and numbers at the end:
where $_.Name -match '_d+$'
If you also want to make sure, that this is actually a versioned copy of another existing folder, you could check that too:
where { $_.FullName -match '^(?<OriginalPath>.+)_d+$' -and (Test-Path $Matches.OriginalPath) }
That looks great, the only issue is there are other folders in there like: - OneDrive.exe - Logs - Help This is why I have an array for looking for folders with numbers in them. :)
– Marshal
Nov 19 '18 at 13:02
1
Marsze, that is one sexy one-liner. I love it.
– Marshal
Nov 19 '18 at 13:42
Hi Marsze, looking at my response to AnsgarWiechers is there anyway to target only those version folders? If I run my full script over and over eventually it breaks down, it could be removing other folders.
– Marshal
Nov 19 '18 at 14:05
1
@Marshal I've extended my answer. I hope that helps you to get started and create your final solution yourself.
– marsze
Nov 20 '18 at 8:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374855%2fremoving-old-folders-and-keeping-the-most-recent%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If the newest folder you want to keep is also the one with the newest creation time, you can use this simple one-liner:
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Directory | sort CreationTime | select -SkipLast 1 | Remove-Item -Recurse -Force
If you want to filter out only a specific type of folders by name, you could use a simple regex match. I cannot help you with the exact regex (since I would have to know your folder naming pattern) but it would look something like this:
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Directory | where Name -match 'dd+' | sort CreationTime | select -SkipLast 1 | Remove-Item -Recurse -Force
(Note that this is syntax might not work if you use an old Powershell version. If that's the case, let me know and I will provide a compatible fallback solution.)
UPDATE
In response to your comment: Your requirements are still a bit unclear, but here is something to get you started:
If you want to make sure to only delete folders that "look like" version folders, you can adjust the regex in the where-filter. _d+$
will match anything with an underscore and numbers at the end:
where $_.Name -match '_d+$'
If you also want to make sure, that this is actually a versioned copy of another existing folder, you could check that too:
where { $_.FullName -match '^(?<OriginalPath>.+)_d+$' -and (Test-Path $Matches.OriginalPath) }
That looks great, the only issue is there are other folders in there like: - OneDrive.exe - Logs - Help This is why I have an array for looking for folders with numbers in them. :)
– Marshal
Nov 19 '18 at 13:02
1
Marsze, that is one sexy one-liner. I love it.
– Marshal
Nov 19 '18 at 13:42
Hi Marsze, looking at my response to AnsgarWiechers is there anyway to target only those version folders? If I run my full script over and over eventually it breaks down, it could be removing other folders.
– Marshal
Nov 19 '18 at 14:05
1
@Marshal I've extended my answer. I hope that helps you to get started and create your final solution yourself.
– marsze
Nov 20 '18 at 8:02
add a comment |
If the newest folder you want to keep is also the one with the newest creation time, you can use this simple one-liner:
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Directory | sort CreationTime | select -SkipLast 1 | Remove-Item -Recurse -Force
If you want to filter out only a specific type of folders by name, you could use a simple regex match. I cannot help you with the exact regex (since I would have to know your folder naming pattern) but it would look something like this:
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Directory | where Name -match 'dd+' | sort CreationTime | select -SkipLast 1 | Remove-Item -Recurse -Force
(Note that this is syntax might not work if you use an old Powershell version. If that's the case, let me know and I will provide a compatible fallback solution.)
UPDATE
In response to your comment: Your requirements are still a bit unclear, but here is something to get you started:
If you want to make sure to only delete folders that "look like" version folders, you can adjust the regex in the where-filter. _d+$
will match anything with an underscore and numbers at the end:
where $_.Name -match '_d+$'
If you also want to make sure, that this is actually a versioned copy of another existing folder, you could check that too:
where { $_.FullName -match '^(?<OriginalPath>.+)_d+$' -and (Test-Path $Matches.OriginalPath) }
That looks great, the only issue is there are other folders in there like: - OneDrive.exe - Logs - Help This is why I have an array for looking for folders with numbers in them. :)
– Marshal
Nov 19 '18 at 13:02
1
Marsze, that is one sexy one-liner. I love it.
– Marshal
Nov 19 '18 at 13:42
Hi Marsze, looking at my response to AnsgarWiechers is there anyway to target only those version folders? If I run my full script over and over eventually it breaks down, it could be removing other folders.
– Marshal
Nov 19 '18 at 14:05
1
@Marshal I've extended my answer. I hope that helps you to get started and create your final solution yourself.
– marsze
Nov 20 '18 at 8:02
add a comment |
If the newest folder you want to keep is also the one with the newest creation time, you can use this simple one-liner:
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Directory | sort CreationTime | select -SkipLast 1 | Remove-Item -Recurse -Force
If you want to filter out only a specific type of folders by name, you could use a simple regex match. I cannot help you with the exact regex (since I would have to know your folder naming pattern) but it would look something like this:
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Directory | where Name -match 'dd+' | sort CreationTime | select -SkipLast 1 | Remove-Item -Recurse -Force
(Note that this is syntax might not work if you use an old Powershell version. If that's the case, let me know and I will provide a compatible fallback solution.)
UPDATE
In response to your comment: Your requirements are still a bit unclear, but here is something to get you started:
If you want to make sure to only delete folders that "look like" version folders, you can adjust the regex in the where-filter. _d+$
will match anything with an underscore and numbers at the end:
where $_.Name -match '_d+$'
If you also want to make sure, that this is actually a versioned copy of another existing folder, you could check that too:
where { $_.FullName -match '^(?<OriginalPath>.+)_d+$' -and (Test-Path $Matches.OriginalPath) }
If the newest folder you want to keep is also the one with the newest creation time, you can use this simple one-liner:
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Directory | sort CreationTime | select -SkipLast 1 | Remove-Item -Recurse -Force
If you want to filter out only a specific type of folders by name, you could use a simple regex match. I cannot help you with the exact regex (since I would have to know your folder naming pattern) but it would look something like this:
Get-ChildItem "$env:LOCALAPPDATAMicrosoftOneDrive" -Directory | where Name -match 'dd+' | sort CreationTime | select -SkipLast 1 | Remove-Item -Recurse -Force
(Note that this is syntax might not work if you use an old Powershell version. If that's the case, let me know and I will provide a compatible fallback solution.)
UPDATE
In response to your comment: Your requirements are still a bit unclear, but here is something to get you started:
If you want to make sure to only delete folders that "look like" version folders, you can adjust the regex in the where-filter. _d+$
will match anything with an underscore and numbers at the end:
where $_.Name -match '_d+$'
If you also want to make sure, that this is actually a versioned copy of another existing folder, you could check that too:
where { $_.FullName -match '^(?<OriginalPath>.+)_d+$' -and (Test-Path $Matches.OriginalPath) }
edited Nov 20 '18 at 8:01
answered Nov 19 '18 at 13:01
marszemarsze
4,60031740
4,60031740
That looks great, the only issue is there are other folders in there like: - OneDrive.exe - Logs - Help This is why I have an array for looking for folders with numbers in them. :)
– Marshal
Nov 19 '18 at 13:02
1
Marsze, that is one sexy one-liner. I love it.
– Marshal
Nov 19 '18 at 13:42
Hi Marsze, looking at my response to AnsgarWiechers is there anyway to target only those version folders? If I run my full script over and over eventually it breaks down, it could be removing other folders.
– Marshal
Nov 19 '18 at 14:05
1
@Marshal I've extended my answer. I hope that helps you to get started and create your final solution yourself.
– marsze
Nov 20 '18 at 8:02
add a comment |
That looks great, the only issue is there are other folders in there like: - OneDrive.exe - Logs - Help This is why I have an array for looking for folders with numbers in them. :)
– Marshal
Nov 19 '18 at 13:02
1
Marsze, that is one sexy one-liner. I love it.
– Marshal
Nov 19 '18 at 13:42
Hi Marsze, looking at my response to AnsgarWiechers is there anyway to target only those version folders? If I run my full script over and over eventually it breaks down, it could be removing other folders.
– Marshal
Nov 19 '18 at 14:05
1
@Marshal I've extended my answer. I hope that helps you to get started and create your final solution yourself.
– marsze
Nov 20 '18 at 8:02
That looks great, the only issue is there are other folders in there like: - OneDrive.exe - Logs - Help This is why I have an array for looking for folders with numbers in them. :)
– Marshal
Nov 19 '18 at 13:02
That looks great, the only issue is there are other folders in there like: - OneDrive.exe - Logs - Help This is why I have an array for looking for folders with numbers in them. :)
– Marshal
Nov 19 '18 at 13:02
1
1
Marsze, that is one sexy one-liner. I love it.
– Marshal
Nov 19 '18 at 13:42
Marsze, that is one sexy one-liner. I love it.
– Marshal
Nov 19 '18 at 13:42
Hi Marsze, looking at my response to AnsgarWiechers is there anyway to target only those version folders? If I run my full script over and over eventually it breaks down, it could be removing other folders.
– Marshal
Nov 19 '18 at 14:05
Hi Marsze, looking at my response to AnsgarWiechers is there anyway to target only those version folders? If I run my full script over and over eventually it breaks down, it could be removing other folders.
– Marshal
Nov 19 '18 at 14:05
1
1
@Marshal I've extended my answer. I hope that helps you to get started and create your final solution yourself.
– marsze
Nov 20 '18 at 8:02
@Marshal I've extended my answer. I hope that helps you to get started and create your final solution yourself.
– marsze
Nov 20 '18 at 8:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374855%2fremoving-old-folders-and-keeping-the-most-recent%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The sample code you posted is broken. Please create a Minimal, Complete, and Verifiable example, then edit your question and post that code along with all errors that code throws. Also, do the names all folders you want processed have the same format? Like, some text optionally followed by an underscore and a number?
– Ansgar Wiechers
Nov 19 '18 at 12:53
Apologies, I have removed the curly bracket below it. This should now work. If the folder is locked by the system you might see a few errors but this would be the folder I would want to avoid and keep.
– Marshal
Nov 19 '18 at 13:00
Please also answer the question from my previous comment.
– Ansgar Wiechers
Nov 19 '18 at 13:05
@AnsgarWiechers Your question is an interesting on. Sooo, the folder is randomly generated. The folder relates to the version so if the folder name for the original version is free then OneDrive will use that. If it's not then it will add an underscore and increment the number. This means that if you have 18.212.1021.0008, 18.212.1021.0008_1, 18.212.1021.0008_2 and delete "18.212.1021.0008" then the next time OneDrive re-creates the folder it will use 18.212.1021.0008. Hence why I want the others removed to stop the folder getting bunged up with lots of folders.
– Marshal
Nov 19 '18 at 13:14