I was curious to make such thing in windows cmd that is taking source.txt file with such names:
User1
User2
User3
User4
User5
User6
Secondly, I have created the destination folder F:\Destination
The task is to iterate with source.txt and if a file from this txt exists at the address F:\Destination
, delete it, if such file does not exist, create a folder with this name.
For example: I have User1.txt
User2.txt
and User3.txt
in F:\Destination
as a result I need to delete them and create folders User4
User5
and User6
Here is my script, but sadly it's doing nothing
for /F "usebackq eol=| delims=" %G in ("source.txt") do if exist
"Destination\%~G" del "Destination\%~G" if not exist "Destination\%~G" md "Destination\%~G"
Looking forward to your suggestions and solutions. Thanks!
Get-Content .\source.txt | ForEach-Object { New-Item -Type Directory -Name $_ }
adding the other logic might also be easier/more readable.