|
8862
|
Programación / Scripting / Re: Ayuda Script batch/powershell
|
en: 12 Junio 2013, 13:24 pm
|
Es muy sencillo: Set /A "Cut=14" & REM Las lineas que queremos conservar, desde abajo. FOR /F %%@ IN ('Type " %File%" ^| Find /v /c ""' ) DO (Set /A "Length= %%@- %Cut%" ) for /f "tokens=1* delims=]" %%A in ('Type " %File%" ^| Find /n /v ""' ) do ( )
PD1: ten en cuenta que ninguna línea empiece con el caracter: "]" PD2: Para una mayor eficacia primero deberías hacerle un "reverse" el archivo de texto (darle la vuelta para que las lineas de abajo queden arriba del todo, y así se procesan primero) y usar el primer script en lugar de este último. Hay muchas aplicaciones commandline para manejar archivos de texto y efectuar todo tipo de acciones... una de ellas es Tail: Tail.exe --lines=14 "kk.txt"
(Con eso consigues hacer lo mismo que hace mi último script) Saludos
|
|
|
8864
|
Programación / Scripting / Re: Ayuda Script batch/powershell
|
en: 12 Junio 2013, 11:48 am
|
Hola, Antes de nada, haz el favor de leer mi firma. Y prueba a usar el siguiente script, de esta manera: TextMan.bat SR 1 14 "kk.txt"
Saludos! TextMan.bat: :: TEXT MANIPULATOR ROUTINE v0.5 :: by Elektro H@cker REM SYNTAX: :: :: TEXTMAN [ACTION] [LINE(S)] [FILE] [TEXT] :: :: * [LINE(S)] parameter is Optional for some actions :: * [TEXT] parameter is Optional for some actions REM ACTIONS: :: :: AB = ADD_BEGINNING * Add text to the beginning of a line. :: AE = ADD_ENDING * Add text to the end of a line. :: E = ERASE * Delete a line. :: I = INSERT * Add a empty line (Or a line with text). :: RL = REPLACE_LINE * Replace a entire line. :: RS = REPLACE_STRING * Replace word from line. :: RSA = REPLACE_STRING_ALL * Replace word from all lines. :: C+ = CHARACTER_PLUS * Delete the first "X" characters from all lines. :: C- = CHARACTER_LESS * Delete the last "X" characters from all lines. :: L+ = LINE_PLUS * Cut the first "X" amount of lines. :: L- = LINE_LESS * Cut the last "X" amount of lines. :: GL = GET_LINE * Delete all except "X" line. :: GR = GET_RANGE * Delete all except "X" range of lines. REM EXAMPLES: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: Delete the line 3 :: :: Call :TEXTMAN E 3 "Test.txt" :: :: :: :: Add a string to the beginning of line 3 :: :: Call :TEXTMAN AL 3 "Test.txt" "Elektro H@cker" :: :: :: :: Add a string to the end of line 3. :: :: Call :TEXTMAN AR 3 "Test.txt" "Elektro H@cker" :: :: :: :: Add a empty line at line 3. :: :: Call :TEXTMAN I 3 "Test.txt" :: :: :: :: Add a line with a word at line 3. :: :: Call :TEXTMAN I 3 "Test.txt" "Elektro H@cker" :: :: :: :: Replace the line 3 with "Elektro H@cker". :: :: Call :TEXTMAN RL 3 "Test.txt" "Elektro H@cker" :: :: :: :: Replace the words "Elektro" to "H@cker" in line 3. :: :: Call :TEXTMAN RS 3 "Test.txt" "Elektro" "H@cker" :: :: :: :: Replace the words "Elektro" to "H@cker" in all lines. :: :: Call :TEXTMAN RSA "Test.txt" "Elektro" "H@cker" :: :: :: :: Delete the first 3 characters in all lines. :: :: Call :TEXTMAN C+ 3 "Test.txt" :: :: :: :: Delete the last 3 characters in all lines. :: :: Call :TEXTMAN C- 3 "Test.txt" :: :: :: :: Delete the first 3 lines. :: :: Call :TEXTMAN L+ 3 "Test.txt" :: :: :: :: Delete the last 3 lines. :: :: Call :TEXTMAN L- 3 "Test.txt" :: :: :: :: Delete all except the line number 3. :: :: Call :TEXTMAN SL 3 "Test.txt" :: :: :: :: Delete all except the 3 to 9 range of lines. :: :: Call :TEXTMAN SR 3 9 "Test.txt" :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :TEXTMAN (SET /A "A=0", "LINE=0", "TOTAL_LINES=0" ) & (CALL : %~1 %* || (ECHO Invalid parameter & Exit /B 1 )) & (GOTO:EOF ) :AB :AE (For /F "tokens=1* delims=]" %%A in ('type " %~3" ^| find /n /v ""' ) DO (Call Set /A "LINE+=1" && (CMD /C " IF NOT " %%LINE%%" EQU "%~2" (if " %%B" EQU "" (Echo+ >> " %~3.NEW" ) ELSE ((Echo %%B)>> " %~3.NEW" )) ELSE ((Echo %%B%~4 )>> " %~3.NEW" )" ))) && (CALL : RENAMER " %~3" ) & (GOTO:EOF ) :E (For /F "tokens=1* delims=]" %%A in ('type " %~3" ^| find /n /v ""' ) DO (Call Set /A "LINE+=1" && (CMD /C " IF NOT " %%LINE%%" EQU "%~2" (if " %%B" EQU "" (Echo+ >> " %~3.NEW" ) ELSE ((Echo %%B) >> " %~3.NEW" ))" ))) && (CALL : RENAMER " %~3" ) & (GOTO:EOF ) :I :RL :RS :RSA (For /F "tokens=1* delims=]" %%A in ('type " %~2" ^| find /n /v ""' ) DO (CALL SET "STRING= %%B" && (if " %%B" EQU "" (Echo+ >> " %~2.NEW" ) ELSE ((CALL ECHO %%STRING:%~3= %~4%%)>>"%~2.NEW" )))) && (CALL : RENAMER " %~2" ) & (GOTO:EOF ) :C+ :C- (For /F "usebackq tokens=*" %%@ in (" %~3" ) DO (Call Set "LINE= %%@" && (CALL ECHO %%LINE:~0,-%~2 %% >> " %~3.NEW" ))) && (CALL : RENAMER " %~3" ) & (GOTO:EOF ) :L+ (Call SET /A "A= %~2" ) && (Call TYPE " %~3" |@MORE + %%A%% > "%~3.NEW" ) && (CALL : RENAMER " %~3" ) & (GOTO:EOF ) :L- (For /F "tokens=1* delims=]" %%A in ('type " %~3" ^| find /n /v ""' ) DO (CALL SET /A "TOTAL_LINES+=1" )) & (CALL SET /A "TOTAL_LINES-= %~2-1" ) & (For /F "tokens=1* delims=]" %%A in ('type " %~3" ^| find /n /v ""' ) DO (Call Set /A "LINE+=1" & Call echo " %%LINE%%!!|@%%TOTAL_LINES%%" >NUL) && (CALL :RENAMER "%~3" && GOTO:EOF ) || (Echo %%B >> " %~3.NEW" )) :GL (Call SET /A "A= %~2" && Call SET /A "A-=1" ) && (Call TYPE " %~3" |@MORE + %%A%% > "%temp %\getline.tmp") && (For /F "tokens=1* delims=]" %%A in ('type " %temp%\getline.tmp" ^| find /n /v ""' ) DO ((if " %%B" EQU "" (Echo+ >> " %~3.NEW" ) ELSE ((Echo %%B)> " %~3.NEW" ))) && ((CALL : RENAMER " %~3" ) & (GOTO:EOF ))) :GR (For /F "tokens=1* delims=]" %%A in ('type " %~4" ^| find /n /v ""' ) DO (Call Set /A "LINE+=1" && (CMD /C " (IF " %%LINE%%" GEQ "%~2" IF " %%LINE%%" LEQ "%~3" (if " %%B" EQU "" (Echo+ >> " %~4.NEW" ) ELSE ((Echo %%B)>> " %~4.NEW" ))) && (IF " %%LINE%%" EQU "%~3" Exit /B 1 )" || ((CALL : RENAMER " %~4" ) & (GOTO:EOF ))))) :RENAMER (REN " %~1" " %~nx1.BAK" ) & (MOVE /Y " %~1.BAK" " %TEMP%\" >NUL) & (REN " %~1.NEW" " %~nx1" ) & (GOTO:EOF )
|
|
|
8866
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 11 Junio 2013, 21:51 pm
|
Entonces este IniReader usa Secciones? No, no lee secciones ni tampoco guarda secciones, no me gustan las secciones ni tampoco las considero útiles, menos para aplicaciones grandes como CCleaner. explicame, como hago para llamar a 2 pcbs desde el mismo .INI Pues primero guardas el valor de cada PictureBox en el ini, y luego obtienes los valores préviamente guardados y los asignas a... a lo que estés intentando asignarlo. Lee los comentarios al principio de la Class, ahí hay ejemplos, no sé que puede resultar tán dificil (de verdad), crea un post porque si con esos ejemplos no te aclara entonces ya no se que más decir. Saludos!
|
|
|
8867
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 11 Junio 2013, 19:59 pm
|
Cargar o guardar valores fácilmente en un archivo INI: #Region " INI Manager " ' [ INI Manager Functions ] ' ' // By Elektro H@cker ' ' Examples : ' ' INI_Manager.Set_Value(".\Test.ini", "TextValue", TextBox1.Text) ' Save ' TextBox1.Text = INI_Manager.Load_Value(".\Test.ini", "TextValue") ' Load ' INI_Manager.Delete_Value(".\Test.ini", "TextValue") ' Delete ' INI_Manager.Sort_Values(".\Test.ini") ' Sort INI File Public Class INI_Manager ''' <summary> ''' The INI File Location. ''' </summary> Public Shared INI_File As String = IO.Path.Combine(Application.StartupPath, Process.GetCurrentProcess().ProcessName & ".ini") ''' <summary> ''' Set a value. ''' </summary> ''' <param name="File">The INI file location</param> ''' <param name="ValueName">The value name</param> ''' <param name="Value">The value data</param> Public Shared Sub Set_Value (ByVal File As String, ByVal ValueName As String, ByVal Value As String) Try If Not IO. File. Exists(File) Then ' Create a new INI File with "Key=Value"" My. Computer. FileSystem. WriteAllText(File, ValueName & "=" & Value, False) Exit Sub Else ' Search line by line in the INI file for the "Key" Dim Line_Number As Int64 = 0 Dim strArray () As String = IO. File. ReadAllLines(File) For Each line In strArray If line.ToLower.StartsWith(ValueName.ToLower & "=") Then strArray(Line_Number) = ValueName & "=" & Value IO. File. WriteAllLines(File, strArray ) ' Replace "value" Exit Sub End If Line_Number += 1 Next Application.DoEvents() My. Computer. FileSystem. WriteAllText(File, vbNewLine & ValueName & "=" & Value, True) ' Key don't exist, then create the new "Key=Value" End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub ''' <summary> ''' Load a value. ''' </summary> ''' <param name="File">The INI file location</param> ''' <param name="ValueName">The value name</param> ''' <returns>The value itself</returns> Public Shared Function Load_Value (ByVal File As String, ByVal ValueName As String) As Object Throw New Exception (File & " not found.") ' INI File not found. Return Nothing Else For Each line In IO. File. ReadAllLines(File) If line.ToLower.StartsWith(ValueName.ToLower & "=") Then Return line.Split("=").Last Next Application.DoEvents() Throw New Exception("Key: " & """" & ValueName & """" & " not found.") ' Key not found. Return Nothing End If End Function ''' <summary> ''' Delete a key. ''' </summary> ''' <param name="File">The INI file location</param> ''' <param name="ValueName">The value name</param> Public Shared Sub Delete_Value (ByVal File As String, ByVal ValueName As String) Throw New Exception (File & " not found.") ' INI File not found. Exit Sub Else Try Dim Line_Number As Int64 = 0 Dim strArray () As String = IO. File. ReadAllLines(File) For Each line In strArray If line.ToLower.StartsWith(ValueName.ToLower & "=") Then strArray(Line_Number) = Nothing Exit For End If Line_Number += 1 Next Array.Copy(strArray, Line_Number + 1, strArray, Line_Number, UBound(strArray) - Line_Number) ReDim Preserve strArray(UBound(strArray) - 1) My. Computer. FileSystem. WriteAllText(File, String. Join(vbNewLine, strArray ), False) Catch ex As Exception MsgBox(ex.Message) End Try End If End Sub ''' <summary> ''' Sorts the entire INI File. ''' </summary> ''' <param name="File">The INI file location</param> Public Shared Sub Sort_Values (ByVal File As String) Throw New Exception (File & " not found.") ' INI File not found. Exit Sub Else Try Dim Line_Number As Int64 = 0 Dim strArray () As String = IO. File. ReadAllLines(File) Dim TempList As New List(Of String) For Each line As String In strArray If line <> "" Then TempList.Add(strArray(Line_Number)) Line_Number += 1 Next TempList.Sort() Catch ex As Exception MsgBox(ex.Message) End Try End If End Sub End Class #End Region
|
|
|
8868
|
Programación / .NET (C#, VB.NET, ASP) / Re: Scroll de Imagenes?
|
en: 11 Junio 2013, 18:47 pm
|
Si no recuerdo mal creo que ese efecto se denomina "Bubble Fish" o "Eye Fish" (Ojo de péz), lo puedes hacer como te ha dicho syntax error. Solo tienes que averiguar el índice de la que es la imágen "central", porque si no la identificas primero, no puedes hacer nada, y entonces ya con esa imágen haces lo que prefieras, o bien usar eventos (mouse hover) para agrandar la imágen cuando se pase el ratón por la imágen, o bien mantenerla agrandada permanéntemente. Saludos
|
|
|
8869
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 11 Junio 2013, 11:56 am
|
Otro código de ORO: Devuelve de la manera más eficaz y sencilla una lista de tipo FileInfo con todos los archivos de un directorio, Le hice dos overloads para poder usar la función de varias maneras y evitar posibles errores en el "SearchPattern", La función es "IgnoreCase", devuelve la extensión en uppercase y lowercase y todas las variantes posibles, en fin, esto es la perfección: #Region " Get Files " ' [ Get Files Function ] ' ' // By Elektro H@cker ' ' Examples : ' ' For Each file In Get_Files("C:\Windows", False) : MsgBox(file.Name) : Next ' ' For Each file In Get_Files("C:\Windows", True, "dll") : MsgBox(file.Name) : Next ' For Each file In Get_Files("C:\Windows", True, ".dll") : MsgBox(file.Name) : Next ' For Each file In Get_Files("C:\Windows", True, "*.dll") : MsgBox(file.Name) : Next ' ' For Each file In Get_Files("C:\Windows", False, {"dll", "ini"}) : MsgBox(file.Name) : Next ' For Each file In Get_Files("C:\Windows", False, {".dll", ".ini"}) : MsgBox(file.Name) : Next ' For Each file In Get_Files("C:\Windows", False, {"*.dll", "*.ini"}) : MsgBox(file.Name) : Next ' Get Files {directory} {recursive} Private Function Get_Files(ByVal directory As String, ByVal recursive As Boolean) As List(Of IO.FileInfo) Dim searchOpt As IO.SearchOption = If(recursive, IO.SearchOption.AllDirectories, IO.SearchOption.TopDirectoryOnly) Return IO.Directory.GetFiles(directory, "*", searchOpt).Select(Function(p) New IO.FileInfo(p)).ToList End Function ' Get Files {directory} {recursive} {ext} Private Function Get_Files(ByVal directory As String, ByVal recursive As Boolean, ext As String) As List(Of IO.FileInfo) If ext.StartsWith("*") Then ext = ext.Substring(1, ext.Length - 1) ElseIf Not ext = "*" AndAlso Not ext.StartsWith(".") Then ext = ("." & ext) ElseIf ext = "*" Then ext = Nothing End If Dim searchOpt As IO.SearchOption = If(recursive, IO.SearchOption.AllDirectories, IO.SearchOption.TopDirectoryOnly) Return IO.Directory.GetFiles(directory, "*" & ext, searchOpt).Select(Function(p) New IO.FileInfo(p)).ToList End Function ' Get Files {directory} {recursive} {exts()} Private Function Get_Files(ByVal directory As String, ByVal recursive As Boolean, ParamArray exts() As String) As List(Of IO.FileInfo) Dim FileExts(exts.Count) As String Dim ExtCount As Int32 = 0 For Each ext In exts If ext.StartsWith("*") Then FileExts(ExtCount) = ext.Substring(1, ext.Length - 1) ElseIf Not ext = "*" AndAlso Not ext.StartsWith(".") Then FileExts(ExtCount) = ("." & ext) ElseIf Not ext = "*" AndAlso ext.StartsWith(".") Then FileExts(ExtCount) = ext ElseIf ext = "*" Then FileExts(ExtCount) = Nothing End If ExtCount += 1 Next Dim searchOpt As IO.SearchOption = If(recursive, IO.SearchOption.AllDirectories, IO.SearchOption.TopDirectoryOnly) Dim filenameExtComparer As New FilenameExtensionComparer Return IO.Directory.GetFiles(directory, "*", searchOpt).Where(Function(o) FileExts.Contains(IO.Path.GetExtension(o), filenameExtComparer)).Select(Function(p) New IO.FileInfo(p)).ToList End Function ' FilenameExtensionComparer Public Class FilenameExtensionComparer : Implements IEqualityComparer(Of String) Public Function Equals1(s As String, t As String) As Boolean Implements IEqualityComparer(Of String).Equals Return String.Compare(s, t, StringComparison.OrdinalIgnoreCase) = 0 End Function Public Function GetHashCode1(s As String) As Integer Implements IEqualityComparer(Of String).GetHashCode Return s.GetHashCode() End Function End Class #End Region
|
|
|
8870
|
Programación / Scripting / Re: Transformar nombre de los archivos a 001,002,003.png,etc?
|
en: 11 Junio 2013, 09:57 am
|
perdón, lo escribí al vuelo y cometí un misstype, símplemente añade un SET /A aquí: PD: La costumbre de no usar keywords a la izquierda de las variables en otros lenguajes cada vez se apodera más de mi xD. Error: Ya existe un archivo con el mismo nombre o no se ha encontrado el archivo.
Ese error que comentas es "normal", si ya tienes un archivo que se llama "1.png" no se puede renombrar al mismo nombre y el bat fallará con ese archivo, pero nada grave. Saludos
|
|
|
|
|
|
|