This is sort of my "Hello World" program; my first ever in the programming language Fortran.
I like to learn lots of programming languages and Fortran was next on my list. I don't really do HW programs as I usually have an idea for what kind of software I want, need, or just want to write something different.
This has been compiled and tested on both Windows and Linux.
$OSI = Get-ComputerInfo
Write-Host ""$OSI.OsName "`n" $OSI.OsVerion
Microsoft Windows 10 Pro
10.0.18363
g95 -o delete delete.f95 # compile
delete.exe *.file # assumming a.file and b.file
Deleting: a.file.
a.file was deleted successfully.
Deleting: b.file.
b.file was deleted successfully.
$ cat /etc/*-release|grep "PRETTY_NAME"|cut -d'=' -f2
"Ubuntu 18.04.4 LTS"
$ uname -a|awk '{print $1" "$3" "$11}'
Linux 4.4.0-18362-Microsoft x86_64
$ gfortran -o delete delete.f95 # compile
$ delete *.file # assumming a.file and b.file
Deleting: a.file.
a.file was deleted successfully.
Deleting: b.file.
b.file was deleted successfully.
program delete
integer::numArgs,getArg,stat,stat_close
logical::file_exists
character(256)::trimArg,thisArg
numArgs=command_argument_count()
if(numArgs>0)then
do getArg=1,numArgs
call get_command_argument(getArg,thisArg)
trimArg=trim(thisArg)
inquire(file=trimArg,exist=file_exists)
if ( file_exists ) then
print *, 'Deleting: ',trim(trimArg), '.'
open(unit=10, iostat=stat, file=trimArg, status='old')
if (stat == 0) close(10, iostat=stat_close,status='delete')
if (stat_close .gt. 0) then
print *, trim(trimArg),' was not deleted.'
else
print *, trim(trimArg),' was deleted successfully.'
end if
else
print *,trim(trimArg), ' does not exist.'
end if
end do
end if
end program delete
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.