Applescript editor can't look for a file - applescript

I needed to write some codes to do this, but Applescript editor can't see if the file (ewqe_file) is existed or not. (It is existed)

Try it this way:
set fullPath to (POSIX path of (path to desktop folder as text)) & "aFolderOnMyDesktop/44034_D.pdf"
tell application "System Events"
if exists file fullPath then
log fullPath
-- do your stuff
end if
end tell
path to command, from StandardAdditions:
path to v : Return the full path to the specified folder
path to application support/applications folder/desktop/desktop pictures folder/documents folder/downloads folder/favorites folder/Folder Action scripts/fonts/help/home folder/internet plugins/keychain folder/library folder/modem scripts/movies folder/music folder/pictures folder/preferences/printer descriptions/public folder/scripting additions folder/scripts folder/services folder/shared documents/shared libraries/sites folder/startup disk/startup items/system folder/system preferences/temporary items/trash/users folder/utilities folder/workflows folder/voices/apple menu/control panels/control strip modules/extensions/launcher items folder/printer drivers/printmonitor/shutdown folder/speakable items/stationery : the folder to return
[from system domain/local domain/network domain/user domain/Classic domain] : where to look for the indicated folder
[as type class] : the type to return: alias or string (default is alias)
[folder creation boolean] : Create the folder if it doesn’t exist? (default is true)
→ alias : the path to the specified folder

The path should be written in this format:
"Macintosh HD:Users:username:Desktop:file.txt"

Related

CI4 - Trying to move image but get error "could not move file php6WkH2s to /var/www/example.com/development.example.com/app_dir/public/ ()

I am trying to upload a file and move it to public/ folder. The file uploads without problem to writable folder, however, it is the moving to the public folder that has a problem.
Here is my code;
$update_post->move(ROOTPATH.'public/', $update_post.'.'.$fileType);
Path is correct. When I echo out echo ROOTPATH.'public/'; and then manually copy/paste, I do get to the destination directory.
Permissions correct. There are my permission on the public/ directory:
drwxr-xr-x 9 www-data www-data 4096 Jan 30 01:08 public
Any hints appreciated.
Reason:
It's because the move(string $targetPath, ?string $name = null, bool $overwrite = false) method's $name argument is invalid.
$update_post->move( ... , $update_post.'.'.$fileType);
Explanation:
Concatenating an class CodeIgniter\Files\File extends SplFileInfo instance calls the inherited SplFileInfo class's __toString() method which returns the path to the file as a string.
Note that it doesn't return the filename, which is what you're interested in.
Solution:
You should instead pass in the basename instead.
$update_post->move(
ROOTPATH . 'public/',
$update_post->getBasename()
);
Alternatively, since you're not changing the destination filename, it's cleaner to just not pass in the second parameter of the move(...) method. I.e:
$update_post->move(
ROOTPATH . 'public'
);
Addendum:
If you wish to change the destination filename to a new name, try this instead:
guessExtension()
Attempts to determine the file extension based on the trusted
getMimeType() method. If the mime type is unknown, will return null.
This is often a more trusted source than simply using the extension
provided by the filename. Uses the values in app/Config/Mimes.php to
determine extension:
$newFileName = "site_logo"; // New filename without suffixing it with a file extension.
$fileExtension = $update_post->guessExtension();
$update_post->move(
ROOTPATH . 'public',
$newFileName . (empty($fileExtension) ? '' : '.' . $fileExtension)
);
Notes:
The move(...) method returns a new File instance for the relocated file, so you must capture the result if the resulting location is needed: $newRelocatedFileInstance = $update_post->move(...);

Absolute paths in build.gradle on Windows

I defined an absolute path in gradle.properties to a keystore
I am using Windows
I have an empty space in the path
RELEASE_STORE_FILE="D:\My Folder\Android\android.javakeystore.keystore.jks"
I receive the error
The filename, directory name, or volume label syntax is incorrect
at java.io.WinNTFileSystem.canonicalize0(Native Method)
at java.io.WinNTFileSystem.canonicalize(WinNTFileSystem.java:428)
at java.io.File.getCanonicalPath(File.java:618)
at java.io.File.getCanonicalFile(File.java:643)
at org.gradle.api.internal.file.FileNormaliser.normalise(FileNormaliser.java:54)
... 222 more
How do I define absolute paths on Windows in Gradle correctly?
Problem is coming from the surrounding " character in your property value from gradle.properties file. You should configure your property in gradle.properties as follows:
RELEASE_STORE_FILE=D:\\My Folder\\Android\\android.javakeystore.keystore.jks
or
RELEASE_STORE_FILE=D:/My Folder/Android/android.javakeystore.keystore.jks
Gradle preserves the " character from properties value, so if you try something like that:
file(RELEASE_STORE_FILE).exits() // if RELEASE_STORE_FILE contains " char, it will fail
Other examples to illustrate this:
gradle.properties
cert_path_1=c:/my certs/cert.txt
cert_path_2="c:/my certs/cert.txt"
cert_path_3="c:\\my certs\\cert.txt"
cert_path_4=c:\\my certs\\cert.txt
build.gradle
void testFile(String message, String fileToTest){
println message
println " -> does the file exist? : " + file(fileToTest).exists() + "\n"
}
testFile("Testing property 'cert_path_1'", ext.cert_path_1)
testFile("Testing property 'cert_path_2'", ext.cert_path_2)
testFile("Testing property 'cert_path_3'", ext.cert_path_3)
testFile("Testing property 'cert_path_4'", ext.cert_path_4)
Result:
Testing property 'cert_path_1'
-> does the file exist? : true
Testing property 'cert_path_2'
-> does the file exist? : false
Testing property 'cert_path_3'
-> does the file exist? : false
Testing property 'cert_path_4'
-> does the file exist? : true

How to write a file in specific path in ruby

I want to save my files in specific path..
I have used like this
file_name = gets
F = open.(Dir.pwd, /data/folder /#{#file_name },w+)
I'm not sure whether the above line is correct or not! Where Dir.pwd tell the directory path followed by my folder path and the file name given.
It should get store the value on the specific path with the specific file name given. Can anyone tell me how to do that.
Your code has multiple errors. Have you ever tried to execute the script?
Your script ends with:
test.rb:7: unknown regexp options - fldr
test.rb:7: syntax error, unexpected end-of-input
F = open.(Dir.pwd, /data/folder /#{#file_name },w+)
First: You need to define the strings with ' or ":
file_name = gets
F = open.(Dir.pwd, "/data/folder/#{#file_name}","w+")
Some other errors:
You use file_name and later #file_name.
The open method belongs to File and needs two parameters.
The file is defined as a constant F. I would use a variable.
The path must be concatenated. I'd use File.join for it.
You don't close the file.
After all these changes you get:
file_name = gets
f = File.open(File.join(Dir.pwd, "/data/folder/#{file_name}"),"w+")
##
f.close
and the error:
test.rb:29:in `initialize': No such file or directory # rb_sysopen - C:/Temp/data/folder/sdssd (Errno::ENOENT)
The folder must exist, so you must create it first.
Now the script looks like:
require 'fileutils'
dirname = "data/folder"
file_name = gets.strip
FileUtils.mkdir_p(dirname) unless Dir.exists?(dirname)
f = File.open(File.join(Dir.pwd, dirname, file_name),"w+")
##fill the content
f.close

Gradle copying and rename files

I have to write gradle task which will be copying files. Files are stored at tests/[Name]/test.txt and for each Name I want to create numbered directory /tested/test00/, /tested/test01/ etc. and in each catalog should be one file (test.txt from source folder renamed to test00, test01 etc.)
I have the code, but behavior is strange...
It creates correct directories /tested/test00 etc. but all files in each directory have the same name... test06. So number in directory is correct but in file name it isn't.
My code is:
int copyTaskIterator = 0
int testIterator = 0
...
sources.each { mySource ->
task "myCopyTask$copyTaskIterator"(type: Copy)
nameSuffix = String.format("%02d", testIterator)
fromPath = 'tests/'+mySource+'/test.txt'
toPath = "tested/test"+nameSuffix
tasks."myCopyTask$copyTaskIterator".from fromPath
tasks."myCopyTask$copyTaskIterator".into toPath
tasks."myCopyTask$copyTaskIterator".rename { fileName ->
fileName.replace '.txt', nameSuffix
}
preBuild.dependsOn tasks."myCopyTask$copyTaskIterator"
copyTaskIterator++
testIterator++
}
The problem is, that nameSuffix is evaluated too late. Sadly no documentation explains whether it is executed in execution time or not.
Just try to use rename(java.util.regex.Pattern, java.lang.String)
tasks."myCopyTask$copyTaskIterator".rename("\\.txt", nameSuffix)

Jscript create folder if not exist

I am trying to create folder when it does not exist. If folder is exist it will skip and continue to create the next folder.
Which part is wrong in this following code,
Error
Micrsoft Jscript runtime error: File already exists
Code
function CreateFolder(fldr)
{
if (fso.FolderExists(fldr)){
return;
}
else
fso.CreateFolder("C:\\"+ fldr);
}
If fldr doesn't include the drive letter, FolderExists looks for this folder in the current wording directory. But your code then creates this folder in C:\. Most likely, the error occurs because there's no folder with this name in the current working directory, but it exists in C:\.
Your code should probably be either
function CreateFolder(fldr)
{
if (! fso.FolderExists(fldr))
fso.CreateFolder(fldr);
}
or
function CreateFolder(fldr)
{
var path = fso.BuildPath("C:", fldr);
if (! fso.FolderExists(path))
fso.CreateFolder(path);
}

Resources