You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done.
#!/bin/sh
# The script is located in /tmp/abc/myscript.sh
export AppPath=$(dirname $0)
echo $0
# /tmp/abc/myscript.sh
echo $AppPath
# /tmp/abc
44
Delphi
Filehandling
Datei auf dem Betriebssystem ausführen
procedure TForm1.MenuDummy1Click(Sender: TObject);
var
ExeName : array[0..255] of char;
myFile : String;
begin
myFile:='winword.exe';
Showmessage('Starte: ' + myFile);
StrPCopy(ExeName, myFile);
ShellExecute(MainForm.Handle, 'open', ExeName, nil, nil, SW_SHOWNORMAL);
// Drucken geht dann so (siehe auch Dateitypen im Windows Explorer):
ShellExecute(MainForm.Handle, 'print', ExeName, nil, nil, SW_SHOWNORMAL);
end;
70
Python
Filehandling
Verzeichnis rekursiv durchsuchen
import os
searchPath = '/home/patrick/Desktop/'
# os.walk will go through all subdirectories
for pathentry in os.walk(searchPath, False):
for dir in pathentry[1]:
path = os.path.join(pathentry[0], dir)
if os.path.islink(path):
print path + "... is a link"
# os.unlink(path)
else:
print path + "... is a dir"
# os.rmdir(path)
for file in pathentry[2]:
path = os.path.join(pathentry[0], file)
# os.unlink(path)
print path + "... is a file"
# os.listdir only the given path
for file in os.listdir(searchPath):
fullfilename = os.path.join(searchPath, file)
if os.path.isfile(fullfilename):
print fullfilename + "... is a file"
import commands
output=commands.getoutput("dir")
print output
# home tmp myFile.sh
175
Bash Script
Filehandling
Verzeichnis rekursiv durchsuchen
# http://wiki.ubuntuusers.de/Shell/Bash-Skripting-Guide_f%C3%BCr_Anf%C3%A4nger#Variablen-Teil-2
#!/bin/bash
for file in /home/myUser/*/*.png ; do
echo "Diese Datei: $file"
fname=$(basename "$file")
echo "hat den Namen: $fname"
fdir=$(dirname "$file")
echo "und steht im Verzeichnis: $fdir"
# Diese Datei: /home/myUser/galaxy.png
# hat den Namen: galaxy.png
# und steht im Verzeichnis: /home/myUser
176
Bash Script
Filehandling
Prüfen ob Datei existiert
# http://wiki.ubuntuusers.de/Shell/Bash-Skripting-Guide_f%C3%BCr_Anf%C3%A4nger#If-Else-Anweisung
#!/bin/bash
filePath="/home/myUser/test.txt"
if [ -f ${filePath} ]
then
echo "There it is! ;-)"
else
echo "Whow, file is missing at this place :-("
fi
177
Delphi
Filehandling
Prüfen ob Datei existiert
procedure TForm1.CheckIfFileExists();
var
filePath : String;
begin
filePath:='C:\User\myUser\text.txt';
if FileExists(filePath) then
begin
ShowMessage('There it is! ;-)');
end
else
begin
ShowMessage('Whow, file is missing at this place :-(');
end;
end;
178
C#
Filehandling
Prüfen ob Datei existiert
String filePath = "C:\\User\\myUser\\text.txt";
if (System.IO.File.Exists(filePath))
{
MessageBox.Show("There it is! ;-)");
}
else
{
MessageBox.Show("Whow, file is missing at this place :-(");
}