Im having problems trying to empty a folder in my script.
This is working in my command line:
rm -r Folder1/Folder2/*
But if in my script I do this:
DIR="Folder1/Folder2/"
rm -r "$DIR*"
It says "rm: Folder1/Folder2/*: No such file or directory", where is the problem?
Im running the script in the same folder as I tried the command.
To delete a file from a directory we use the rm command in Linux/UNIX . rm [OPTION]... [FILE]... Using shell script, we have to delete the input file from every directory above the present working directory. The filename will be passed as an argument.
The generic command is: To delete files and folders, use the Get-ChildItem command and use the Delete () method on the output. Here, this command will delete a file called “testdata.txt”. The above command may not work for folders, especially if they are not empty.
You can either use the Remove-Item cmdlet of PowerShell or the Delete () method that comes by default with every PowerShell object, including folders and files. Both require some knowledge of PowerShell scripts to use the available parameters and efficiently remove files and folders from your system.
The generic command is: To delete files and folders, use the Get-ChildItem command and use the Delete () method on the output. Here, this command will delete a file called “testdata.txt”.
Glob expansion doesn't happen inside quotes.
Try:
rm -r -- "$DIR"*
(Just make really sure you don't put a space after the quotes.)
rm -r $DIR*
That should work, without quotes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With