How to create a file on windows with filename starting with ' ' space?
For testing purpose I need a file with filename starting with space.
In database such files are stored and I am unable to retrieve the same due to space.
Open a command line and type: notepad " test.txt" then save the file
Related
I have an AppleScript that is used to programmatically create a test script file in one of these Office 2016 app folders:
~/Library/Application Scripts/com.microsoft.Excel
~/Library/Application Scripts/com.microsoft.Word
~/Library/Application Scripts/com.microsoft.Powerpoint
This is the test.scpt file content which is programmatically generated:
on handlerTest(thisPhrase)
say thisPhrase
end handlerTest
This test.scpt file contains a single handler which speaks the phrase passed to it.
When the script is created in one of these folders, I cannot see the content of the script file in Finder and calling the handler from a Microsoft Office app using the new VBA AppleScriptTask causes the Office app to crash. I think the script is being created as a byte-compiled file because it cannot be viewed in Finder as plain text.
If I then copy the script file generated programmatically by my script creator script to the Documents folder, the plain-text content of the script is viewable in Finder.
Now, if I copy the script file from the Documents folder back to the corresponding com.microsoft folder (without modifying it), I can now see the plain-text content in Finder and calling the handler using the VBA AppleScriptTask function works as expected. I don't understand how the format is apparently changing due to copy/paste actions?
How can I programmatically create the script file in the com.microsoft.xyz folder in plain text format?
Here is my VBA procedure:
Sub TestScript()
AppleScriptTask "test.scpt", "handlerTest", "hello world"
End Sub
Here is my example script creator script which programmatically creates a test.scpt file in the com.microsoft.Powerpoint scripting folder: (kudos to eliteproxy for the original source script)
property theFolders : {"~/Library/'Application Scripts'/com.microsoft.Powerpoint"}
try
tell application "Finder" to set targetFolder to (target of the front window) as alias
on error -- no window
set targetFolder to (choose folder)
end try
# build a parameter string from the folder list
set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
set {theFolders, AppleScript's text item delimiters} to {theFolders as text, tempTID}
do shell script "cd " & quoted form of POSIX path of targetFolder & "; mkdir -p " & theFolders
--Write the Script file if it does not exist
if ExistsFile("~/Library/'Application Scripts'/com.microsoft.Powerpoint/test.scpt") is false then
tell application "Finder"
--GET THE WORKING DIRECTORY FOR FILE COPY OF SCRIPT
get folder of (path to me) as Unicode text
set workingDir to POSIX path of result
--Write the new script in the current working directory
set textFile to workingDir & "test.scpt"
--Delete script if it exists
set posixPath to POSIX path of textFile as string
do shell script "rm -rf \"" & posixPath & "\""
--Create Script Interface file for Microsoft PowerPoint VBA Applications
set fd to open for access textFile with write permission
-- Create test handler which speaks the passed phrase parameter
write "on handlerTest(thisPhrase)" & linefeed to fd as «class utf8» starting at eof
write "say thisPhrase" & linefeed to fd as «class utf8» starting at eof
write "end handlerTest" & linefeed to fd as «class utf8» starting at eof
close access fd
--Copy the script file into the MACOS-Specific 'safe' folder
set fromPath to quoted form of POSIX path of (workingDir) & "test.scpt"
set toPath to quoted form of "~/Library/'Application Scripts'/com.microsoft.Powerpoint"
do shell script "cp -R " & fromPath & space & "~/Library/'Application Scripts'/com.microsoft.Powerpoint" with administrator privileges
end tell
end if
--Delete the temp script file from the working directory
set posixPath to POSIX path of textFile as string
do shell script "rm -rf \"" & posixPath & "\""
--Provide confirmation
set theAlertTitle to "TEST"
set theAlertMsg to "The script has been successfully installed."
display alert theAlertTitle message theAlertMsg as informational buttons {"OK"} default button "OK" cancel button "OK"
--For use when checking if a file exists
on ExistsFile(filePath)
tell application "System Events" to return (exists disk item filePath) and class of disk item filePath = file
end ExistsFile
I could be wrong in my interpretation of your question, but it appears as if you are looking to create file “Test.scpt” with your handler “handlerTest” as the code, in a folder named “com.microsoft.Excel” (for example). If that is all you are looking to achieve, I believe this solution should work for you...
script theHandler
on handlerTest(thisPhrase)
say thisPhrase
end handlerTest
end script
storeScript()
on storeScript()
set thisScript to store script theHandler in (path to home folder as text) ¬
& "Library:Application Scripts:com.microsoft.Excel:Test.scpt" replacing yes
end storeScript
So, basically, without having any Visual Studio experience, I wanted to improve my animation workflow. So, I wanted to use stuff found in http://www.aseprite.org/cli/ to do that.
So, I made a little program to get all .ase files in a folder and make a text file containing the lines needed for the batch file to convert the said .ase files to either .gif or png files. I'm stupid, so I manually convert the text file to a .bat file.
But the .txt files generated from the program do not work when converted to .bat, but if I copy the lines to another .txt file I create in windows, and convert it to .bat, it works.
So the question is - do I corrupt the .txt file in Visual Studio or something?
If there's a problem with the code, I'll share it, but I'm reluctant, cause I don't want to have a formatting mistake nightmare.
Oh, and yeah, I know this isn't a smart way to go about.
EDIT: Ah, right, the error of the batch file, which, by the way, flashed by extremely quickly and closes the command line prompt: '--batch' is not recognized as an internal or external command, operable program or batch file.
The code in .bat is like:
#set ASEPRITE="C:\Program Files\Aseprite\aseprite.exe"
%ASEPRITE% --batch animation.ase --scale 2 --save-as animation-x2.gif
%ASEPRITE% --batch animation.ase --scale 4 --save-as animation-x4.gif
And basically in VB I create the txt file and text like this:
' Dim fs As FileStream = File.Create(Label1.Text + "\Text.txt")
fs.Close()
For Each foundFile As String In My.Computer.FileSystem.GetFiles(Label1.Text)
Dim check As String = System.IO.Path.GetExtension(foundFile)
If check = ".ase" Then
ListBox1.Items.Add(Dir(foundFile))
str = Dir(foundFile)
str = str.Replace(".ase", fType)
My.Computer.FileSystem.WriteAllText(Label1.Text + "\Text.txt",
"%ASEPRITE% --batch " + Dir(foundFile) + " --scale " + fSize + " --save-as " + str + vbCrLf,
True)
End If
Next
'
You can try to write the file with a specific encoding:
File.WriteAllText(path, text, Encoding.UTF8) ' or UTF or ASCII
It could also be that the UTF8 encoder uses a Byte Order Mark which can't be read:
File.WriteAllText(path, text, new UTF8Encoding(false))
The other thing to look for is end of line characters. Is it \r\n or just \n?
You can use a file comparer to check the difference between the files, and it should become clear what the difference is.
I have read the following advice for converting UTF-8 encoded(Hebrew) XLS to CSV via Google Docs, and it worked. When I open the CSV in Sublime2 with UTF8 encoding the Hebrew is showing correctly. But then, when I try to import the Data to My DB using SQLyog, after making sure that both my target table and the import definitions are set to UTF8, I get gibberish, like: מדרשות
Where did I go wrong?
The best way to export from excel to csv is:
Open the excel file and click on "Save as..."
Insert a name and then in "Save as File Type" select "CSV (Comma delimited)"
Then, click on "Tools" and select "Web Options"
Go to "Encoding", under the option "Save this document as" select "Unicode (UTF-8)".
Listo! I couldn't leave the answer in the proper question : (
Original post found> eHow(spanish)
Some images of this.
In Microsoft Excel, open the *.xlsx file.
Select Menu | Save As.
Enter any name for your file.
Under "Save as type," select Unicode Text.
Click Save.
Open your saved file in Microsoft Notepad.
Replace all tab characters with commas (",").
Select a tab character (select and copy the space between two column headers)
Open the "Find and Replace" window (Press Ctrl+H) and replace all tab characters with comma .
Click Save As.
Name the file, and change the Encoding: to UTF-8.
Change the file extension from ".txt" to ".csv".
Click Save.
Open the .csv file in Excel to view your data.
source: https://help.salesforce.com/articleView?id=000003837&type=1
For development purpose, I need to change regularly an Excel file and to generate a "CSV" file that is a text file where column's elements are separated by TAB character.
To facilitate my work, I have created following VBS script
'***********************************************************************
'* file: SaveAs.CSV.bat
'***********************************************************************
sInputFile = Wscript.Arguments(0)
WScript.Echo "Excel input file: " & sInputFile
Set ex = CreateObject("Excel.Application")
Set wb = ex.Workbooks.Open(sInputFile)
ex.Application.DisplayAlerts = False
'https://learn.microsoft.com/en-us/office/vba/api/office.msoencoding
wb.WebOptions.Encoding = 28591
ex.Application.DefaultWebOptions.Encoding = 28591
'https://learn.microsoft.com/en-us/office/vba/api/excel.xlfileformat
sOutputFile = Replace(sInputFile & "*",".xlsx*",".txt")
ex.Worksheets(1).SaveAs sOutputFile, 20
ex.ActiveWorkbook.Close
ex.Application.Quit
WScript.Echo "CSV file has been created."
WScript.Quit
To start "CSV" file creation for a specific XLSX file, I have created following BAT file
cscript SaveAs.CSV.vbs "D:\Documents\+Informatique\Application\#Visual Basic.NET\DrawPlanUnifilaire\Plan-Unifilaire.xlsx"
pause
So, I only click on BAT file and a TXT tab separated file is automatically generated from first sheet in XLSX file.
The UNICODE UTF8 characters contained in XLSX file (éèàüäù) are correctly converted to Windows ANSI characters.
The solution I came up with was skipping the conversion from CSV to SQL using RegExp. Something like:
FIND: "(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)"
REPLACE: INSERT INTO aminadav VALUES (NULL,$1,"$2",$3,"$4","$5","$6","$7","$8","$9","$10");
here i am reading files from one root folder and after reading that we are moving that particular file Success folder and taking a copy of that in to back up folder normal
while reading file i will check file naming convention by targeting backup folder if suppose it was exists in backup folder then i m moving the file to duplicate folder
my problem if suppose again same file came to process this file already existed in duplicate folder how do send the file in to duplicate folder, unfornately i dint have any property as file rename any way can anybody give some suggestion to resolve from issue please.
If File.Exists(Swift_Backup + "\" + Path.GetFileName(CBFile)) Then
' File.Move(CBFile, Swift_Duplicate + "\\" + Path.GetFileName(CBFile)) 'DUPLICATE FOLDER'
' File.Copy(oldFileName, NewFileName);
File.Copy(CBFile, Swift_Duplicate + "\\" + Path.GetFileNameWithoutExtension(CBFile) + "_" + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + Path.GetExtension(CBFile)) 'DUPLICATE FOLDER'
File.Delete(CBFile)
END IF
i have tried like this but was not worked out for am i did any mistake
Swift_Duplicate --> duplicate folder name
Swift_Backup --> backup folder name
CBFile --> string filename will be there in cbfile, it will fetch from the root folder
Renaming a file is the same as moving it to the same directory with a different name. For example:
File.Move("C:\\docs\\new.doc", "C:\\docs\\old.doc");
Also, consider using FileInfo class:
FileInfo file = new FileInfo("C:\\docs\\new.doc");
file.MoveTo("C:\\docs\\new.doc");
FileInfo copy = file.CopyTo("C:\\docs\\old.doc");
I have a compiled AppleScript application which I have moved to my windows server. I'd like to then insert a text file into the application (which looks like a zip file on windows):
myapplescript.app/Contents/Resources/MyNewDir/MyTxtFile.txt
So, I've precompiled the AppleScript to try to read from this text file and get the contents as a string. This is what I do:
set theFolder to POSIX path of (the path to me)
set theFile to theFolder & "Contents/Resources/MyNewDir/MyTxtFile.txt"
open for access theFile
set fileContents to (read theFile)
close access theFile
but this is the error I get:
Can't make
"/Users/mike/Desktop/myapplescript.app/Contents/Resources/MyNewDir/MyTxtFile.txt"
into type file
Ok, I figured it out, I changed the second line to this:
set theFile to (POSIX file (theFolder & "Contents/Resources/MyNewDir/MyTxtFile.txt"))
There is also a single line version of read:
read POSIX file "/tmp/test.txt" as «class utf8»
Both versions use MacRoman unless you add as «class utf8». (as Unicode text is UTF-16.)
Reading a file via a file path in a variable.
The 1st two work. The 3rd, which stores the file name in variable does not.
set myData to read file POSIX file ¬
"/Users/sww/Devel/afile.csv"
set myData to read file ¬
"Macintosh HD:Users:sww:Devel:afile.csv"
set fRef to "Macintosh HD:Users:sww:Devel:afile.csv"
set myData to read file fRef -- No good
To fix? Give the file reference as a string.
set myData to read file (fRef as string) -- OK