Autor Beitrag
KanneM
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26
Erhaltene Danke: 1

Win98, Win XP, Win 7
Java, C#
BeitragVerfasst: Do 07.06.12 16:34 
Liebe Community,

bevors kommt: Ich habe im Forum gesucht und mit Google, beidesmal nichts gefunden!

Problem ist folgendes: Ich will Verzeichnisse rekursiv auslesen, dazu muss ich unterscheiden ob der Pfad auf ne Datei ider ein Verzeichnis deutet. Bisher bin cih wie folgt vorgegangen:
ausblenden C#-Quelltext
1:
if(pfad.Contains(".")){...}					

Nachdem in der vollen URL aber zwangsläufig Punkte vorkommen (ftp.SERVER.de, usw.), habe ich das immer weng unsauber gelöst.

Frage: Gibt es eine Lösung, mit der man abfragen könnte, ob der Pfad auf ne Datei oder n Verzeichnis deutet? Also quasi so änhlich wie
ausblenden C#-Quelltext
1:
if(pfad.IsFile()){...}					


Danke schonmal und ruhigen Feiertag noch,

Kanne
Palladin007
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1282
Erhaltene Danke: 182

Windows 11 x64 Pro
C# (Visual Studio Preview)
BeitragVerfasst: Do 07.06.12 16:52 
Dass du da nichts gefunden hast, glaub ich nicht so ganz...
Naja, wie dem auch sei. So direkt ne Methode gibt es dafür ja auch nicht.


Zu prüfen, was das in dem Pfad nun ist, geht ganz einfach:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
static string CheckPath(string Path)
{
    if (System.IO.Directory.Exists(Path))
        return "Directory";
    else if (System.IO.File.Exists(Path))
        return "File";
    else return "NotExist";
}

(Hab das hier grad so aus dem Stegreif getippt, wenn jemand Schreibfehler findet, bitte verzeihen^^)



Ganz einfaches Prinzip, oder?
KanneM Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26
Erhaltene Danke: 1

Win98, Win XP, Win 7
Java, C#
BeitragVerfasst: Fr 08.06.12 07:59 
Ja das ist klar, aber ich bin/war der Überzeugung das geht nur für Systempfade? (C://NeuerOrdner/Datei.txt)
Sollte es so sein: Ich bräuchte das ganze ja für Online-Pfade (server.de/Verzeichnis/Datei.txt oder server.de/Datei.txt)

Ich werde das später mal testen, melde mich nochmal falls es geht :)

Danke schonmal,
Kanne

EDIT: Es geht wirklich nicht...


ausblenden C#-Quelltext
1:
2:
3:
4:
if(System.IO.Directory.Exists("http://SERVER.de/DATEI.txt"))
                    MessageBox.Show("OK");
                else
                    MessageBox.Show("Fehler");
Palladin007
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1282
Erhaltene Danke: 182

Windows 11 x64 Pro
C# (Visual Studio Preview)
BeitragVerfasst: Fr 08.06.12 16:03 
Ok, dann muss ich mich ausklinken.

Mit der Online-Technologie bin ich noch nicht so fit
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Sa 09.06.12 09:47 
Hallo Michi,

es kann ja sowohl Verzeichnisse mit Punkt als auch Dateinamen ohne Punkt geben.
Da wirst du wohl einen FtpWebRequest mit dem Befehl ListDirectoryDetails absetzen müssen und dann die Antwort parsen:
How to: List Directory Contents with FTP
Sample code for parsing FtpWebRequest response for ListDirectoryDetails (hier dann auf FileStruct.IsDirectory prüfen)

Für diesen Beitrag haben gedankt: KanneM
KanneM Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26
Erhaltene Danke: 1

Win98, Win XP, Win 7
Java, C#
BeitragVerfasst: So 10.06.12 17:05 
Ich habe mir es jetzt so überlegt, dass ich Datein und Ordner Liste und dann dementsprechend sortiere.

Danke euch^^