ronmanp Posted October 16, 2007 Posted October 16, 2007 hi what can I do if I want to test if a folder named corb.dir exist ? I tried :if exist c:\corb.dirbut I get a error with this ...can anybody help ? ps: the folder has to have the dot in it
IcemanND Posted October 16, 2007 Posted October 16, 2007 if exist c:\corb.dir ( echo yes) else ( echo no)PauseWorks just fine here.
jaclaz Posted October 16, 2007 Posted October 16, 2007 The "usual" way to check for the existence of a directory (no matter if it has a dot in the name) is to check for the nul device inside it. Under NTFS or Novell it is more correct to check for nul.ext, i.e.:if exist corb.dir\nul ECHO YESor (better)if exist corb.dir\nul.ext ECHO YESReference here:http://www.msfn.org/board/Batch_Scripts_Im..._Ap_t98853.htmljaclaz
Yzöwl Posted October 16, 2007 Posted October 16, 2007 C:\>if exist c:\program files\nul (@echo/folder found) else (@echo/folder not found)C:\>if exist "c:\program files\nul" (@echo/folder found) else (@echo/folder not found)folder not foundC:\>if exist c:\program files (@echo/folder found) else (@echo/folder not found)C:\>if exist "c:\program files" (@echo/folder found) else (@echo/folder not found)folder foundC:\>if exist c:\windows\nul (@echo/folder found) else (@echo/folder not found)folder foundC:\>if exist "c:\windows\nul" (@echo/folder found) else (@echo/folder not found)folder not foundC:\>if exist c:\windows (@echo/folder found) else (@echo/folder not found)folder foundC:\>if exist "c:\windows" (@echo/folder found) else (@echo/folder not found)folder foundIf you were to give us an example and show us the actual location of the unrecognised directory, then a more fitting reply could be formulated.
gunsmokingman Posted October 16, 2007 Posted October 16, 2007 Here is the way to do it using a VBS script.I tested this using a folder called New.FolderSave As CheckFolder.vbs Dim Act :Set Act = CreateObject("Wscript.Shell") Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")'/-> The Folder To Check For Place Folder Path Here Dim Folder :Folder = "New.Folder" If Fso.FolderExists(Folder) Then WScript.Echo "Confirm " & Folder Act.Run(Chr(34) & Folder & Chr(34)),1,False Else WScript.Echo "Missing " & Folder End If
[deXter] Posted October 19, 2007 Posted October 19, 2007 If spaces in folder names are a problem, then you can just refer them by their 8.3 equivalent.Eg: "C:\Program Files" = "C:\PROGRA~1"
ronmanp Posted October 23, 2007 Author Posted October 23, 2007 (edited) thanks for the replies guys but Im still having problems I get "goto was unexpected at this time" the purpose of this batch file is to create a command that will "safe" delete the files by moving them to c:/corb.dir/@echo offrem ========================================================================rem sdel.cmdrem date : 23 octobre 2007rem but: Automatiser des tâches dans un environnement Windowsrem ========================================================================if not %2=="" goto langueif %1=="" goto langueif %1=="/?" goto langueif not exist %1 goto erreurif not exist c:\corb.dir\nul mkdir c:\corb.dir\ goto deplacer if exist c:\corb.dir\%~n1 choice /c:oyn /t:n,05 Écraser le fichier SpecFICH (O)ui ,(N)on?: Overwrite file FileSPEC (Y)es or (N)o if errorlevel 3 goto finif errorlevel 2 goto deplacerif errorlevel 1 goto deplacer:deplacermove %~n1 c:\corb.dir\:languechoice /c:fe Quel langue préférez-vous ? / What language do you prefer (F)rançais ou / or (E)nglish?:if errorlevel 2 goto anglaisif errorlevel 1 goto francais:francaisecho SYNTAXE : sdel [SPECFICH][/?]echo SPECFICH : Représente une spécification de fichier selon la syntaxeecho echosuivante : [lecteur :][chemin]nomfich[.ext]echo Exemple 1 : sdel /? (affiche cet écran d’aide)echo Exemple 2 : sdel toto (Déplace le fichier toto dans c:\corb.dir) pause :anglaisecho SYNTAX : sdel [FILESpec][/?]echo FILESpec : Represents a file specification using the following syntax:echo [drive :][path]filename[.ext]echo Example 1 : sdel /? (Shows this help screen)echo Example 2 : sdel toto (Moves toto to the recycle bin c:\corb.dir)pause:erreurecho Fichier SpecFICH introuvable – File FileSPEC not foundpause :fin Edited October 23, 2012 by ronmanp quote tags replaced by codebox tags
Yzöwl Posted October 23, 2007 Posted October 23, 2007 As I've already suggested without response, I need to know what OS this script will be running! Based on the use of 'choice' I would have thought Windows 9x.In quick respose to your direct question however, changeif not exist c:\corb.dir\nul mkdir c:\corb.dir\ goto deplacertoif not exist c:\corb.dir\nul ( mkdir c:\corb.dir goto deplacer)
jaclaz Posted October 23, 2007 Posted October 23, 2007 A small "side" suggestion. When using the GOTO or CALL statement, it is advisable to follow them with complete name of the label (including the ":" ) this way it is easier to find them at a glance.As Yzöwl pointed out, this is wrongif not exist c:\corb.dir\nul mkdir c:\corb.dir\ goto deplaceryou cannot put two statements after an IF without grouping the commands with parenthesis or using the "&" sign:if not exist c:\corb.dir\nul mkdir c:\corb.dir\&goto :deplacershould work as welljaclaz
ronmanp Posted October 23, 2007 Author Posted October 23, 2007 (edited) thanks guys I managed to make it work ! ps: I needed to make it work on a Windows 2003 server Edited October 23, 2007 by ronmanp
Yzöwl Posted October 23, 2007 Posted October 23, 2007 I'm glad you got it working, however the batch file is not very well written, and will not work as you expect.For example, when you've ran the command under your deplacer label, you will be asked for your language choice. Similar behaviour will occur after most of your label sections have ran.
ronmanp Posted October 23, 2007 Author Posted October 23, 2007 (edited) I think I fixed it by moving my deplacer label to the end ..here my final version (sent to the teacher) rem sdel.cmdrem par : My namerem date : 23 octobre 2007rem but: Automatiser des tâches dans un environnement Windowsrem ========================================================================if NOT "%2" == "" GOTO langueif "%1" == "" GOTO langueif "%1" == "/?" GOTO langueif NOT EXIST "%1" GOTO erreurif EXIST c:\corb.dir\%~n1 choice /c:oyn /t:n,05 Écraser le fichier SpecFICH (O)ui ,(N)on?: Overwrite file FileSPEC (Y)es or (N)o if errorlevel == 3 goto finif errorlevel == 2 goto deplacerif errorlevel == 1 goto deplacerif NOT EXIST c:\corb.dir\nul mkdir c:\corb.dir\ GOTO deplacer :langueecho Quel langue préférez-vous? / What language do you prefer (F)rançais ou / or (E)nglish?:choice /c:fe if errorlevel == 2 GOTO anglaisif errorlevel == 1 GOTO francais:francaisecho SYNTAXE : sdel [SPECFICH][/?]echo SPECFICH : Représente une spécification de fichier selon la syntaxeecho suivante : [lecteur :][chemin]nomfich[.ext]echo Exemple 1 : sdel /? (affiche cet écran d’aide)echo Exemple 2 : sdel toto (Déplace le fichier toto dans c:\corb.dir)echo Appuyez sur une touche pour quitter….pause>nulgoto fin:anglaisecho SYNTAX : sdel [FILESpec][/?]echo FILESpec : Represents a file specification using the following syntax:echo [drive :][path]filename[.ext]echo Example 1 : sdel /? (Shows this help screen)echo Example 2 : sdel toto (Moves toto to the recycle bin c:\corb.dir)echo Hit any key to quit…pause>nulgoto fin:erreurecho Fichier SpecFICH introuvable – File FileSPEC not foundgoto fin:deplacermove /Y "%1" c:\corb.dir\%~n1:fin Edited November 19, 2012 by ronmanp
Yzöwl Posted October 23, 2007 Posted October 23, 2007 It's starting to look a little better, but what have you gone and done to the 'if errorlevel' commands? you've got whitespace you don't want in them now!
ronmanp Posted October 23, 2007 Author Posted October 23, 2007 hum my choice command works well ? how should I change it ?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now