Access VBA - Rename File With Periods In The Name - ms-access

So, I'm attempting to rename a file (Enrollment tracking 07.30.xlsx) to "Enrollment tracking.xlsx", but it hates the period in the date, and it won't do it.
Path = "V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\"
OriginalName = Dir("V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\*Enrollment tracking*")
NewName = "V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\Enrollment tracking.xlsx"
Name Path & OriginalName As NewName
It will toss the runtime error 75: "Path/File access error"...
Is there any way to do this? I can get it to identify the file name with the "OriginalName" variable (it will show as "Enrollment tracking 07.30.xlsx"), but I can't get it to rename the file.

The periods aren't the issue, its the path.
Take a closer look at your last line:
Name Path & OriginalName As NewName
The issue is that you already put the path in the variable OriginalName, as shown below:
Path = "V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\"
OriginalName = Dir("V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\*Enrollment tracking*")
so, you're trying to rename the file under Path & Originalname, which would be:
"V:\CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\V:\
CORPDATA17\MBRSHIPANDBILL\Alegeus Migration Tracker\Daily Reports\
*Enrollment tracking*"
Which would understandibly cause an error.
Try replacing your last line with simply:
Name OriginalName As NewName
I tried this approach on my computer and it worked, here's my full code:
Sub changeFileName()
origFile = "C:\Users\name\Desktop\1.2.3.txt"
NewFile = "C:\Users\name\Desktop\123.txt"
Name origFile As NewFile
End Sub
EDIT: you can actually use the Dir() function, when I tested the code above I forgot to include it. This code also worked for me, so maybe there's an error in file/path name? that's what the error seems to indicate. See code:
Sub changeFileName2()
Path = "C:\Users\name\Desktop\"
origFile = Dir("C:\Users\name\Desktop\1.2.3.txt")
NewFile = "C:\Users\name\Desktop\123.txt"
Name Path & origFile As NewFile
End Sub

Related

Work with list variable in python 3 and delete folders based on it

Sorry if I named it wrong, this is my first try in python make some working script. I made list with Dictionary Cursor, but I need now to work with is as variables and delete folders. For example.
If I will found in /data/system/domain.tld and domain.tld is listed in from my select in ["name"] I want to delete that directory. How should I proceed with my code when I want this functionality?
import pymysql.cursors
import os
connection = pymysql.connect(host='localhost',
user='root',
password='password',
db='database',
cursorclass=pymysql.cursors.DictCursor)
cursor = connection.cursor()
sql="SELECT id, name, state FROM domain WHERE state='2'"
cursor.execute(sql)
records = cursor.fetchall()
print("Total number of records for deleting is: ", cursor.rowcount)
print("\nPrinting each domain record")
for row in records:
print (row)
print("id = ", row["id"], )
print("name = ", row["name"])
print("state = ", row["state"], "\n")
Assuming the above syntax is working correctly, i.e. producing rows where the row[name] values are the paths of the directories you wish to delete, then you should just need to add the delete command to your for loop as a new line.
Delete a file or folder
The above link has a lot more information on how to delete files and folders using Python. Looking at the top answer, the shutil.rmtree() function looks like it should delete a directory based on a given path.
You can find the shutil documentation here
So, if you wanted to continue to print all those variables, your for loop should just need the additional line with the shutil.rmtree() function:
for row in records:
print (row)
print("id = ", row["id"], )
print("name = ", row["name"])
print("state = ", row["state"], "\n")
shutil.rmtree(row["name"])

MYSQL + Change path + Update substring

I have a question, i have table 'file' with a column 'path' in my DB called Pics.
Each path is like "C:\my folder\pics\pic1.jpg" etc.......
How i do to change:
C:\my folder\pics\
to
C:\my NEW folder\NEW pics\
I try a select for the path folder without the filename like this :
SELECT substring(c1,1,locate(substring_index(c1,'/',-1),c1)-1) FROM t1
that give me "C:\my folder\pics\".
Now i need to update all the column path. What is the correct query. I try this but dont work.
update foto set path = 'z' where path = (SELECT substring(path,1,locate(substring_index(path,'\\',-1),path)-1))
Thanks for sharing
Done.
update foto set path = REPLACE(path,(SELECT substring(path,1,locate(substring_index(path,'\\',-2),path)-1)),'" & TextBox2.Text & "'

Error trying to Upload image using srrs using rs.exe -"The required field Property is missing from the input structure"

Scenario : Upload image using srrs using rs.exe (using code not GUI)
Environment : Sql server 2012, rs.exe , vb.script
'Utility to Publish the Png file ( snippet)
'Sample inputs PublishImageFile("myimagefilename.png", "image/png")
Public Sub PublishImageFile(ByVal imageName As String,ByVal resourceMIME As String)
Try
Dim stream As FileStream = File.OpenRead(filePath + "\" + imageName)
definition = New [Byte](stream.Length - 1) {}
stream.Read(definition, 0, CInt(stream.Length))
stream.Close()
Catch e As IOException
Console.WriteLine(e.Message)
End Try
imageName = imageName.tostring.replace(".png", "")
Console.WriteLine("Attempting to Deploy Resource Name {0}", imageName.tostring)
Dim item As CatalogItem
Dim mimeProperty As New Microsoft.SqlServer.ReportingServices2010.Property
mimeProperty.Name = "MimeType"
mimeProperty.Value = resourceMIME
Dim properties(1) As Microsoft.SqlServer.ReportingServices2010.Property
properties(0) = mimeProperty
Try
item = rs.CreateCatalogItem("Resource", imageName, ReportFolder, True,
definition, properties, warnings) 'Error line
'More code below removed for brevity
Error I receive in the last line above is
The required field Property is missing from the input structure. ---> Microsoft.ReportingServices.Diagnostics.Utilities.MissingElementException: The required field Property is missing from the input structure.
What are the required parameters required in the properties object to fix the issue.
I did not find the same in CreateCatalogitem method in MSDN
https://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010.createcatalogitem(v=sql.120).aspx
Nor in the Catalog item description in MSDN
https://msdn.microsoft.com/en-us/library/reportservice2010.catalogitem.aspx
From the error message and investigation it appears ( my assumption) like a required field named 'Property' could missing from the properties array. But what would be its value?
Please share your suggestions & solutions or may be even an code alternative to rs.exe to automate deploy images to ssrs using script.
I found the answer. I just added an additional property named property and name as filename just before the CreateCatalogItem method and it worked!
Dim propertyItem As New Microsoft.SqlServer.ReportingServices2010.Property
propertyItem.Name = "Property"
propertyItem.Value = imageName
properties(1) = propertyItem

System.Data.OleDb.OleDbException: Invalid path or file name

i have the following code which has been getting me data from flat files. but now all of a sudden i am getting this error
System.Data.OleDb.OleDbException: Invalid path or file name
but the code hasnt changed it worked for months,im not sure what went wrong.
System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();
string jsonText;
System.Collections.Generic.List<object> objList = new List<object>();
string strConn = #"Provider=vfpoledb;Data Source=\\10.0.0.0\wwwroot\apps\assembly\FlatDatabaseDbfs\vt_Flat.dbf;Collating Sequence=machine;";
using (System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn))
{
System.Data.OleDb.OleDbCommand cmddbf = new System.Data.OleDb.OleDbCommand();
cmddbf.Connection = conn;
conn.Open();
cmddbf.CommandText = "select * from vt_Flat";
var dr = cmddbf.ExecuteReader();
while (dr.Read())
{
objList.Add(new
{
Code = (dr["dp_code"].ToString().Trim()),
});
};
}
var filteredList = objList.Where(obj => ((dynamic)obj).Status == (Request.QueryString["Status"] ?? "") && ((dynamic)obj).DepCode == (Request.QueryString["Code"] ?? ""));
jsonText = json.Serialize(filteredList);
Response.Write(jsonText);
}
is there something wrong with iis permissions?
Aside from the connection having to point to the PATH as already noted by Oleg, in the C# instances of OleDbConnection I have done in the past, the connection string uses
Provider=VFPOLEDB.1
Don't know if it is case/sensitive issue and the ".1" which is also part of the provider string.
Once you have a valid connection to the PATH, then your query can query from any table within the path location. So if you had 2+ files, and needed to join them, you would do so with a standard query / join. In your case, your command text is only "select *" since you changed your original connection that included the table. Change the command text to
"select * from vt_Flat"
OTHER CONSIDERATIONS
Is this being run from some web service project? If so, THAT could be the basis. You as a developer testing are running with your permissions / access. If running as a web server, the WEB-based user account may not have permissions to the folder to process / work with the data.
Check the folder of your production data to ALLOW the web user if so running. If that doesn't work, set permissions on the folder to EVERYBODY (only for testing/confirmation purposes only). See if that is the problem.
Also, from the Provider connection, did you try with it as all upper case VFPOLEDB.1?
Use path instead of file name, e.g.:
Data Source=\\10.0.0.0\wwwroot\apps\assembly\FlatDatabaseDbfs\;

ä stored as ä value is encoded in database

I write out a variable on the asp page:
name="ända"
response.write name
It shows ända on the page, good!
When inserting it into the database, the value written to the database is ända
The page is encoded with <%Response.charset="iso-8859-1"%>
How can I get this value ända to be written to the database?
<%Response.charset="iso-8859-1"%>
folderName=request.querystring("foretagsnamn")
folderName = replace(folderName, "å" , "a")
folderName = replace(folderName, "ä" , "a")
folderName = replace(folderName, "ö" , "o")
folderName = replace(folderName, "Å" , "a")
folderName = replace(folderName, "Ä" , "a")
folderName = replace(folderName, "Ö" , "o")
folderName = LCase(folderName)
response.write folderName
And then just a sql insert to the database.
sql="INSERT INTO users(folderName) VALUES('"&folderName&"');"
conn.execute(sql)
Its a mySql database, classic asp.
The querystring comes from a creditcard payment service, and the strange thing is that when I perform a transaction and I resive the querystring, it is wrong, but if I then just update the page so it runs the code and querystring again, it is right!?
URL parameters are URL-encoded, and you need to decode URL parameter values to get the original values.
For example, see this implementation of URLDecode
In case of ända, this is HTML-encoded, and you find an HTML decoding function at the same address.
Not sure why you get an HTML encoded string as result of querystring().
Ahh - use Bind Parameters instead of just concatenating your SQL statement together. That solves a number of problems (performance, sql injection attacks, etc)
EDIT: I haven't played with MySQL in a while, but the idea is this:
command = new Command("INSERT INTO USERS(folderName) VALUES (#folderName)");
command.Parameters.Add(new MySqlParameter("#folderName", DbType.NVarChar, 255, folderName));
command.ExecuteNonQuery();
Also, folderName must be a unicode column (NCHAR or NVARCHAR).
It seems to be passed via querystring as the wrong value. Where is the value coming from? That seems to be where the problem is being created.