flat assembler
Message board for the users of flat assembler.

Index > Windows > How can I tell if a path is a file or directory?

Author
Thread Post new topic Reply to topic
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 15 Jun 2010, 03:56
I'm making an quick app to create symbolic links in Windows. There's no good app to do this, but there is an API call. One of the params asks whether the target is a file or directory, how can I tell?

Just to show I'm not asking another dumb theoretical question, here's my code(it's sloppy):
Code:
format pe console
entry start
include 'win32ax.inc'
section '.text' code readable writeable executable

start:
   push      printf_Target
   call      [printf]
   add       esp,4
   push      strTarget
   push      scanf_get_path
   call      [scanf]
   add       esp,8
   push      printf_Location
   call      [printf]
   add       esp,4
   push      strLocation
   push      scanf_get_path
   call      [scanf]
   add       esp,8
   push      strTarget
   call      [printf]
   add       esp,4
   call      newline
   push      strLocation
   call      [printf]
   add       esp,4
   call      newline
   push      printf_yn
   call      [printf]
   add       esp,4
   push      charAnswerYN
   push      scanf_yn
   call      [scanf]
   add       esp,8
   cmp       charAnswerYN,'y'
   je        .correct
   cmp       charAnswerYN,'Y'
   jne       .incorrect
   .correct:
; Test if dir or file and create link here...
   .incorrect:
   push 0
   call [ExitProcess]

strNewLine db 0dh,0ah,0
newline:
   push      strNewLine
   call      [printf]
   add       esp,4
   ret

section '.data' data readable writeable
   scanf_get_path db '%255s',0
   scanf_yn db '%1s',0
   printf_Location db 'Location: ',0
   printf_Target db 'Target: ',0
   printf_yn db 'Correct? (Y/N): ',0

section '.bss' readable writable
   strLocation rb 255
   strTarget rb 255
   charAnswerYN rb 2

section '.idata' import data readable writeable

   library kernel,'kernel32.dll',\
           msvcrt,'msvcrt.dll'

   import kernel,\
          CreateSymbolicLinkA,'CreateSymbolicLinkA',\
          ExitProcess,'ExitProcess'

   import msvcrt,\
          printf,'printf',\
          scanf,'scanf'        
    
Post 15 Jun 2010, 03:56
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 15 Jun 2010, 04:04
Tyler wrote:
There's no good app to do this

http://elsdoerfer.name/=ntfslink

_________________
This is a block of text that can be added to posts you make.
Post 15 Jun 2010, 04:04
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 15 Jun 2010, 04:10
To not really answer your question: Whenever I work with files and directories, I use FindFirstFile and FindNextFile, and get that information from them.

To answer your question: GetFileAttributes and the attribute
FILE_ATTRIBUTE_DIRECTORY 16 0x0010
Post 15 Jun 2010, 04:10
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 15 Jun 2010, 04:12
Umm... Nah. I'd prefer to just make a simple app that will accomplish the same task without wasting HDD space.

Thanks for the suggestion though. After I realize I suck and give up coding my own, I'll use that one.

Edit: Thanks, that's exactly the thing I was looking for.
Post 15 Jun 2010, 04:12
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 15 Jun 2010, 10:42
Tyler,

Never ever let someone or something discourage you from trying to accomplish some task. Even if you don't complete it, you often learn something useful by the way (NTFS reparse point concept, for example).
Post 15 Jun 2010, 10:42
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 15 Jun 2010, 20:15
The thing about giving up was a joke, and I think we all already know I suck Wink. Thanks for being supportive though, your a nice person Smile. The thanks was for his suggestion, that function was what I failed to find after ~3 hrs googling and searching msdn.
Post 15 Jun 2010, 20:15
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 16 Jun 2010, 03:07
Wow. What a waste of time. When I saw "symbolic link," I thought Linux-style seamless symbolic links. Turns out, the "CreateSymbolicLink" function just creates a .lnk file.
Post 16 Jun 2010, 03:07
View user's profile Send private message Reply with quote
score_under



Joined: 27 Aug 2009
Posts: 27
score_under 20 Jun 2010, 19:32
1. Create a directory.
2. Open it with CreateFile.
3. http://msdn.microsoft.com/en-us/library/aa364595%28VS.85%29.aspx

And that's how you symlink. Only works on NTFS, so check for that first too.
Post 20 Jun 2010, 19:32
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.