FileSystemObject(FSO) °³Ã¼ ¸ðµ¨·Î ÇÁ·Î±×·¡¹ÖÇÏ·Á¸é
FSO °³Ã¼ ¸ðµ¨ÀºScrrun.dll ÆÄÀÏ¿¡ ÀÖ´Â Scripting Çü½Ä ¶óÀ̺귯¸®¿¡ Æ÷ÇԵǾî ÀÖ´Ù.
µû¶ó¼ FSO °³Ã¼ ¸ðµ¨À» »ç¿ëÇÏ·Á¸é À¥ ¼¹öÀÇ ÀûÀýÇÑ ½Ã½ºÅÛ µð·ºÅ͸®¿¡ Scrrun.dllÀÌ ÀÖ¾î¾ß ÇÑ´Ù.
¸ÕÀú, CreateObject ¸Þ¼µå¸¦ »ç¿ëÇÏ¿© FileSystemObject °³Ã¼¸¦ ¸¸µç´Ù.
¾Æ·¡ ÄÚµå´Â FileSystemObject ÀνºÅϽº¸¦ ¸¸µå´Â ¹æ¹ýÀ» º¸¿©ÁØ´Ù.
<SCRIPT language=JScript> var fso; fso=new ActiveXObject('Scripting.FileSystemObject'); </SCRIPT>
<SCRIPT language=VBScript> Dim fso Set fso=CreateObject("Scripting") </SCRIPT>
µÎ ¿¹Á¦ ¸ðµÎ¿¡¼ ScriptingÀº Çü½Ä ¶óÀ̺귯¸®ÀÇ À̸§ÀÌ°íFileSystemObject´Â ¸¸µé·Á´Â °³Ã¼ÀÇ À̸§ÀÌ´Ù.
´Ù¸¥ °³Ã¼¸¦ ¸¸µå´Â Ƚ¼ö¿Í´Â °ü°è¾øÀÌ FileSystemObject °³Ã¼ ÀνºÅϽº´Â Çϳª¸¸ ¸¸µé ¼ö ÀÖ´Ù.
µÑ°, FileSystemObject °³Ã¼ÀÇ ÀûÀýÇÑ ¸Þ¼µå¸¦ »ç¿ëÇÑ´Ù. ¿¹¸¦ µé¾î, »õ °³Ã¼¸¦ ¸¸µé·Á¸é CreateTextFileÀ̳ª CreateFolder¸¦ »ç¿ëÇÑ´Ù(FSO °³Ã¼ ¸ðµ¨Àº µå¶óÀ̺긦 ¸¸µé°Å³ª »èÁ¦ÇÏ´Â ±â´ÉÀº Áö¿øÇÏÁö ¾ÊÀ½).
°³Ã¼¸¦ »èÁ¦ÇÏ·Á¸é FileSystemObject °³Ã¼ÀÇ DeleteFile ¸Þ¼µå¿Í DeleteFolder ¸Þ¼µå ¶Ç´Â File °³Ã¼¿Í Folder °³Ã¼ÀÇ Delete ¸Þ¼µå¸¦ »ç¿ëÇ϶ó. ÀûÀýÇÑ ¸Þ¼µå¸¦ »ç¿ëÇϸé ÆÄÀÏÀ» º¹»çÇϰųª À̵¿ÇÒ ¼öµµ ÀÖ´Ù.
Âü°í ; FileSystemObject °³Ã¼ ¸ðµ¨ ±â´É Áß ÀϺδ Áߺ¹µÈ´Ù. ¿¹¸¦ µé¾î, ÆÄÀÏÀ» º¹»çÇÒ ¶§ FileSystemObject °³Ã¼ÀÇ CopyFile ¸Þ¼µå¸¦ »ç¿ëÇÒ ¼öµµ ÀÖ°í File °³Ã¼ÀÇ Copy ¸Þ¼µå¸¦ »ç¿ëÇÒ ¼öµµ ÀÖ´Ù. µÎ ¸Þ¼µå´Â »ç¿ë ¹æ½ÄÀÌ ¶È°°À¸¸ç ÇÁ·Î±×·¡¹ÖÀÇ À¶Å뼺À» À§ÇØ Á¦°øµÈ´Ù.
±âÁ¸ µå¶óÀ̺ê, ÆÄÀÏ, Æú´õ¿¡ ¾×¼¼½ºÇÏ·Á¸é FileSystemObject °³Ã¼ÀÇ Get ¸Þ¼µå¸¦ »ç¿ëÇ϶ó.
±âÁ¸ ÆÄÀÏ¿¡ ¾×¼¼½ºÇÏ·Á¸é ¾Æ·¡¿Í °°ÀÌ ÇÑ´Ù.
<SCRIPT language=JScript> var fso,fileObj; fso=new ActiveXObject('Scripting.FileSystemObject'); fileObj=fso.GetFile('c:\\JsTest\\test.txt'); </SCRIPT>
<SCRIPT language=VBScript> Dim fso,fileObj Set fso=CreateObject("Scripting,FileSystemObject") Set fileObj=fso.GetFile("c:\JsTest\test.txt") </SCRIPT>
Create ÇÔ¼ö´Â °³Ã¼¿¡ ´ëÇÑ ÇÚµéÀ» ¹ÝȯÇϱ⠶§¹®¿¡ »õ·Î ¸¸µç °³Ã¼¿¡ Get ¸Þ¼µå¸¦ »ç¿ëÇؼ´Â ¾ÈµÈ´Ù.
¿¹¸¦ µé¾î, CreateFolder ¸Þ¼µå·Î »õ Æú´õ¸¦ ¸¸µç °æ¿ì¿¡´Â Name, Path, Size µîÀÇ ¼Ó¼º¿¡ ¾×¼¼½ºÇϱâ À§ÇØ GetFolder ¸Þ¼µå¸¦ »ç¿ëÇؼ´Â ¾ÈµÈ´Ù. »õ·Î ¸¸µç Æú´õ¿¡ ´ëÇÑ ÇÚµéÀ» °¡Á®¿À·Á¸é CreateFolder ÇÔ¼ö¿¡ º¯¼ö¸¦ ¼³Á¤ÇÑ ÈÄ ¼Ó¼º, ¸Þ¼µå, À̺¥Æ® µî¿¡ ¾×¼¼½ºÇØ¾ß ÇÑ´Ù.
CreateFolder ÇÔ¼ö¿¡ º¯¼ö¸¦ ¼³Á¤ÇÏ·Á¸é ¾Æ·¡ ±¸¹®À» »ç¿ëÇÑ´Ù.
<SCRIPT language=JScript> function CreateFolder(folderPath){ var fso,folderObj; fso=new ActiveXObject('Scripting.FileSystemObject'); if (fso.FolderExists(folderPath)) fso.DeleteFolder(folderPath); folderObj=fso.CreateFolder(folderPath); return '¸¸µç Æú´õ: '+folderObj.Name; } </SCRIPT> <DIV class=show onClick="this.innerHTML=CreateFolderTest('c:\\JsTest\\createFolder')">Æú´õ ¸¸µé±â</DIV>
Folder°¡ ÀÌ¹Ì Á¸ÀçÇÏ¸é ¿À·ù°¡ ¹ß»ýÇÏ°Ô µÇ¹Ç·Î »èÁ¦ÇÏ°í »ý¼ºÇÏ¿´´Ù.
<SCRIPT language=VBScript> Sub CreateFolder Dim fso,fileObj Set fso=CreateObject("Scripting,FileSystemObject") If (fso.FolderExists(folderPath)) Then fso.DeleteFolder(folderPath) End If Set folderObj=fso.CreateFolder(folderPath); CreateFolder='¸¸µç Æú´õ: '&folderObj.Name End Sub </SCRIPT>
°³Ã¼¿¡ ´ëÇÑ ÇÚµéÀÌ ÀÖÀ¸¸é °³Ã¼ÀÇ ¼Ó¼º¿¡ ¾×¼¼½ºÇÒ ¼ö ÀÖ´Ù.
¿¹¸¦ µé¾î, ƯÁ¤ Æú´õÀÇ À̸§À» °¡Á®¿À·Á¸é ¸ÕÀú °³Ã¼ ÀνºÅϽº¸¦ ¸¸µç ÈÄ ÀûÀýÇÑ ¸Þ¼µå·Î(ÀÌ °æ¿ì¿¡´Â Æú´õ°¡ ÀÌ¹Ì Á¸ÀçÇϱ⠶§¹®¿¡ GetFolder ¸Þ¼µåÀÓ) ÇÚµéÀ» °¡Á®¿Â´Ù.
GetFolder ¸Þ¼µå¿¡ ´ëÇÑ ÇÚµéÀ» °¡Á®¿À·Á¸é ¾Æ·¡ Äڵ带 »ç¿ëÇÑ´Ù.
<SCRIPT language=JScript> var folderObj=fso.GetFolder('c:\\'); </SCRIPT>
<SCRIPT language=VBScript> Set folderObj=fso.GetFolder("c:\") </SCRIPT>
ÀÌÁ¦ Folder °³Ã¼¿¡ ´ëÇÑ ÇÚµéÀ» °¡Á®¿Ô±â ¶§¹®¿¡ ¿¹¸¦ µé¾î Name ¼Ó¼ºÀ» È®ÀÎÇÒ ¼ö ÀÖ´Ù.
<SCRIPT language=JScript> var folderObj=fso.GetFolder('c:\\'); document.write('Æú´õ À̸§: '+folderObj.Name); </SCRIPT>
<SCRIPT language=VBScript> Set folderObj=fso.GetFolder("c:\") document.write "Æú´õ À̸§: "&folderObj.Name </SCRIPT>
¿¹¸¦µé·¯ ÆÄÀÏÀ» ¸¶Áö¸·À¸·Î ¼öÁ¤ÇÑ ½Ã°£(DateLastModified)À» ãÀ¸·Á¸é ¾Æ·¡ ±¸¹®À» »ç¿ëÇÑ´Ù.
<SCRIPT language=JScript> function testModiDate(){ var fso,fileObj; fso=new ActiveXObject('Scripting.FileSystemObject'); fileObj=fso.GetFile('c:\\JsTest\\testfile.txt'); // Äõ¸®¿¡ »ç¿ëÇÒ File °³Ã¼¸¦ °¡Á®¿Â´Ù. return '¸¶Áö¸·À¸·Î ÆÄÀÏÀ» ¼öÁ¤ÇÑ ½Ã°£: '+fileObj.DateLastModified; // Á¤º¸¸¦ Ãâ·ÂÇÑ´Ù. } </SCRIPT>
<SCRIPT language=VBScript> Sub testModiDate Dim fso,fileObj Set fso=CreateObject("Scripting,FileSystemObject") Set fileObj=fso.GetFile("c:\Jstest\testfile.txt") ' Äõ¸®¿¡ »ç¿ëÇÒ File °³Ã¼¸¦ °¡Á®¿Â´Ù. testModiDate="¸¶Áö¸·À¸·Î ÆÄÀÏÀ» ¼öÁ¤ÇÑ ½Ã°£: " &fileObj.DateLastModified ' Á¤º¸¸¦ Ãâ·ÂÇÑ´Ù. End Sub </SCRIPT>