os.rename not changing file extension in windows - windows

I have a simple Python 3's script that rename all files in a folder, in the shell it shows the new name applied correctly, but when I go to the folder in windows, the files does not have any extension.
i.e: In python I rename somefile to: "newname.jpg", but on windows it is only "newname", without extension. I guess this is more a Windows 10's problem than a Python's problem.
This is the code:
import os
from os import listdir
i = 0
dir = "./PHOTO GALLERY 1"
for archivo in listdir(dir):
i=i+1
if i<10:
j="0"+str(i)
else:
j=str(i)
print ("Nombre original: " + archivo)
os.rename(dir + "/" + archivo, dir + "/" + "photogallery1_" + j)
print ("Nombre nuevo: " + "photogallery1_" + j + ".jpg")

It looks like you're leaving off the file extension:
os.rename(dir + "/" + archivo, dir + "/" + "photogallery1_" + j)
should be
os.rename(dir + "/" + archivo, dir + "/" + "photogallery1_" + j + ".jpg")
like in your print statement.

Related

Can't chage the wireframe name and output

I am using the Corona to render and I made a program to automate multiple renders. When run the script, the program generates a .jpeg of the asset with the material and texture and a wireframe image. The problem is that the wireframe don't have his name updated on each image and is not being saved inside the folder that the user selects.
rendSaveFile = true
_frame = 0
studioFile = getOpenFileName caption: "Select the Studio Asset"
loadMaxFile studioFile
directoryParent = getSavePath caption: "Select the Parent Directory"
dirPath = directoryParent + "\*"
dirList = getDirectories dirPath
print dirList
renderPath = getSavePath caption: "Select a Folder to Save the Renders"
for dir in dirList do(
assetsPath = dir + "\*.max"
assetsList = getFiles assetsPath
print assetsList
for current in assetsList do(
xrefs.addNewXRefFile current
currentName = getFilenameFile current
makeDir (renderPath + "\\" + currentName)
finalPath = (renderPath + "\\" + currentName)
for c in cameras where classof c != Targetobject do(
render camera:c outputfile:(finalPath + "\\" + currentName + "_" + c.name + "_" + ".jpeg")
if c.name == "CAM_RENDER_TURN" then(
makeDir (finalPath + "\\" + "360")
turnPath = (finalPath + "\\" + "360")
render camera:c fromframe:0 toframe:10 outputfile:(turnPath + "\\" + currentName + "_" + _frame as string + ".jpeg")
_frame += 1
)
)
xrefs.deleteAllXRefs()
)
)

Dir function error "wrong number of arguments or invalid property assignment"

I have made a control panel within vb6, and in one of the forms, I want the user of the program to change the name of the existing text file or rewrite it. I am using the Dir function as shown below:
If Check3.Value = 1 Then
If Dir(File.Path + " \ " + Form2.filetext.Text, vbNormal) <> 0 Then
intfile = MsgBox("File existing. Do you want to delete the existing file?", vbYesNo, "WARNING")
If intfile = 6 Then
Open File.Path + "\" + Form2.filetext.Text For Output As #3
Else
Open File.Path + "\" + Form2.filetext.Text For Append As #3
End If
Else
Open File.Path + "\" + Form2.filetext.Text For Output As #3
End If
Else
Close #3
End If
End Sub
But when I chose my file or changing the name, the Dir function gives me this error
wrong number of arguments or invalid property assignment
I would appreciate it if you could help me.
Change Line
If Dir(File.Path + " \ " + Form2.filetext.Text, vbNormal) <> 0 Then
to
If Dir(File.Path + "\" + Form2.filetext.Text, vbNormal) <> "" Then
Add "Option Explicit" without Quotes on top of code of form and check for undeclared variable

Ruby - Parsing XML with Nokogiri

I'm not familiar with XML and trying to get a bit network automation going. I get some XML responses like the following, and try to convert it to a hash or something to easily work with it. I have no idea if I'm doing something wrong. I get the output shown below.
Anyone can push me into a direction ? I tried the nokogiri documentation and guides, but I'm kinda lost.
My Data:
"show ip int brief vrf all | xml\r\n" +
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
"<nf:rpc-reply xmlns:nf=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns=\"http://www.cisco.com/nxos:1.0:ip\">\n" +
" <nf:data>\n" +
" <show>\n" +
" <ip>\n" +
" <interface>\n" +
" <__XML__BLK_Cmd_ip_show_interface_command_brief>\n" +
" <__XML__OPT_Cmd_ip_show_interface_command_operational>\n" +
" <__XML__OPT_Cmd_ip_show_interface_command_vrf>\n" +
" <__XML__OPT_Cmd_ip_show_interface_command___readonly__>\n" +
" <__readonly__>\n" +
" <TABLE_vrf>\n" +
" <ROW_vrf>\n" +
" <vrf-name-out>management</vrf-name-out>\n" +
" </ROW_vrf>\n" +
" </TABLE_vrf>\n" +
" <TABLE_intf>\n" +
" <ROW_intf>\n" +
" <intf-name>mgmt0</intf-name>\n" +
" <prefix>10.70.237.15</prefix>\n" +
" <ip-disabled>FALSE</ip-disabled>\n" +
" <iod>316</iod>\n" +
" <proto-state>up</proto-state>\n" +
" <link-state>up</link-state>\n" +
" <admin-state>up</admin-state>\n" +
" </ROW_intf>\n" +
" </TABLE_intf>\n" +
" </__readonly__>\n" +
" </__XML__OPT_Cmd_ip_show_interface_command___readonly__>\n" +
" </__XML__OPT_Cmd_ip_show_interface_command_vrf>\n" +
" </__XML__OPT_Cmd_ip_show_interface_command_operational>\n" +
" </__XML__BLK_Cmd_ip_show_interface_command_brief>\n" +
" </interface>\n" +
" </ip>\n" +
" </show>\n" +
" </nf:data>\n" +
"</nf:rpc-reply>\n" +
2.4.1 :363 > doc = Nokogiri::XML(my_data)
=> #<Nokogiri::XML::Document:0x173dda8 name="document">
2.4.1 :364 > doc.elements
=> []
Get rid of anything before <?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> XML declaration - in you case, omit "show ip int brief vrf all | xml\r\n" line.
Once your document is parsed, follow official tutorial on searching - for a beginner IMHO it's best to avoid Xpath and just stick with .css selectors, which will be easy to grasp if you've ever done any CSS or Jquery.

Accessing wsadmin objects via Jython

I'm trying to access the Admin objects via a Jython script in order to update a Maven app deployed to a WebSphere Application Server without having to march through the Integrated Solutions Console every time I make a change. My question is simple: I know how to invoke the commands once I access the Admin objects, but I'm having difficulty getting that far. Once I'm in the bin folder of my server profile, do I need to assign them to objects, or can I just call them directly? And how, specifically, would I do that? Here's the code I have now:
#!usr/bin/local/python
import sys
import os
try:
serverPath = 'c:\IBM\WebSphere8\AppServerND\profiles\\WAS8\\bin\\'
os.chdir(serverPath)
print AdminApp.listModules('restreportscore-application')
except:
e = sys.exc_info()[0]
print( "Error: %s" % e )
endSelect = raw_input("Press Enter to continue...")
But it's throwing an error of type 'exceptions.NameError.'
It doesn't work the way it looks like you think it works. The jython interface mirrors the cmd line actions, but isn't the same. You call a jython script like this:
sudo /opt/IBM/WebSphere/AppServer/bin/wsadmin.sh lang jython -f ./trecs-installer.py
So it already knows "where" it is. At that point you execute your commands through the AdminApp, AdminConfig and AdminTask APIs like this:
AdminApp.install(earDir + "trecs.ear", "[" + settings + ' -MapModulesToServers [' + mapModulesToServers + '] -MapRolesToUsers [' + mapRolesToUsers + "]")
or
# Add destinations and queues...
for item in trecsQueues:
if isNetworkDeploy:
AdminTask.createSIBDestination("[-bus " + trecsBus + " -name " + item + " -type Queue -reliability ASSURED_PERSISTENT -cluster " + clusterName + ']')
AdminTask.createSIBJMSQueue(clusterLongName, "[-name " + item + " -jndiName queue/" + item + " -busName " + trecsBus + " -queueName " + item + ']')
else:
AdminTask.createSIBDestination("[-bus " + trecsBus + " -name " + item + " -type Queue -reliability ASSURED_PERSISTENT -node " + nodeName + ' -server ' + serverName + ']')
AdminTask.createSIBJMSQueue(serverLongName, "[-name " + item + " -jndiName queue/" + item + " -busName " + trecsBus + " -queueName " + item + ']')

Parameters in Crystal Reports from Visual Studio 2010

My report donĀ“t accept the parameter.
I have created a parameter with "City" name.
In my code i want to full it:
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("CrystalReport.rpt"));
crystalReport.SetParameterValue("City", lblCiudad.Text);
viewer.ReportSource = crystalReport;
the problem is that the report doesnt filter with my parameter, show without it.
Solution with formula:
crystalReportViewer.SelectionFormula = "{Clientes.Nombre} = '" + nombreCliente + "' AND {Registros.Host} = '" + host + "' AND {Registros.Servicio} = '" + service + "' AND {Registros.Fecha} <= " + "DateTime(" + fF.Year.ToString() + "," + fF.Month.ToString() + "," + fF.Day.ToString() + ","+fF.Hour.ToString() + "," + fF.Minute.ToString()+","+fF.Second.ToString()+") AND {Registros.Fecha} >= " + " DateTime(" + fI.Year.ToString() + "," + fI.Month.ToString() + "," + fI.Day.ToString() + ","+fI.Hour.ToString() + "," + fI.Minute.ToString()+","+fI.Second.ToString()+")";

Resources