c# - Should I Be Using the @ or // Symbol with Providing Paths from Command Line -


i'm developing command-line utility , passing paths arguments inside batch file. need add @ symbol paths within application prevent characters "\" escaping?

this link specifies using @ symbol, currently, i'm not using @ or \\ prevent escaping. when pass in path is, works fine. why this?

i call this, inside batch file:

foldercleaner.exe -tpath: "c:\users\someuser\directorytoclean" 

program:

class program     {         public static void main(string[] args)         {             if(args[0] == "-tpath:" || args[0] == "-tpath:"  && !isblank(args[1]))  {                     clearpath(args[1]);             }             else{                  console.writeline("parameter either -tpath:/-tpath: , must provide valid path");             }     }   

clear path method:

public static void clearpath(string path)         {             if(directory.exists(path)){                  int directorycount = directory.getdirectories(path).length;                  if(directorycount > 0){                      directoryinfo di = new directoryinfo(path);                      foreach (directoryinfo dir in di.getdirectories())                     {                         dir.delete(true);                      }                  }                 else{                      console.writeline("no subdirectories remove");                 }                  int filecount = directory.getfiles(path).length;                  if(filecount > 0){                      system.io.directoryinfo di = new directoryinfo(path);                      foreach (fileinfo file in di.getfiles())                     {                             file.delete();                      }                   }                 else{                      console.writeline("no files remove");                 }                  }             else{                  console.writeline("path doesn't exist {0}", path);             }         } 

escaping of special characters (like " or ) needed inside of string literals within code:

var str = "this literal"; var str2 = othervariable; //this not literal 

no need escape characters when calling application.

however, when using batch example, there might different set of special characters different types of escape characters. example, if want pass "%" (from batch) need pass escape sequence "%%".


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -