How can i delete a directory (folder) that contains files or/and other folders in j2me?
I know how to use fileconnection but it can not delete a folder that contains other folders or files.
well, if your device doesn't allow deletion of non-empty folders, presumably, delete every file in the folder first, then delete the empty folder...
Here is the some code..
String url="file:///localhost/somedir"; //in some devices localhost will be root or user
FileConnection localdir=(FileConnection)Connector.open(url,Connector.READ_WRITE);
if(localdir.exists())
{
Enumeration list=localdir.list(); //gives u total files list (files +dir)
while(list.hasMoreElements())
{
String fileName=(String)list.nextElement();
FileConnection localfile=(FileConnection)Connector.open(url+"/"+fileName,Connector.READ_WRITE);
if(localfile.exists())
localfile.delete();
}
//atlast delete the directory too
localdir.delete();
}
delete all the files and directories and then delete the original directory.
hope this will help..
Related
I am trying to learn rust, and my current objective is to be able to locate .js files in the user's documents directory under a subfolder.
I can currently list all js files in said subfolder.
if let Some(user_dir) = UserDirs::new() {
let script_path = user_dir.document_dir().unwrap().join("test").join("**").join("*.js");
dbg!(&script_path);
for script in glob(script_path.to_str().unwrap()).unwrap(){
dbg!(script);
}
}
This would do nothing in the case where the folder test didnt exist.
How would I go on about handling this case and furthermore create the folder test?
This would do nothing in the case where the folder test didnt exist. How would I go on about handling this case
Store the intermediate path and call Path::exists.
furthermore create the folder test?
fs::create_dir_all.
So I was trying to delete all my files inside a folder using node.
I came across 2 methods .
Method 1
Delete the folder using rmkdir. But if I plan on adding the images on the same folder then I use mkdir and creates the same folder again and appends the files to it.
Example: I have an Add Files and Delete ALL button. When I click deleteAll , the folder gets deleted. And when I click add then the folder gets created and the file gets added to that folder
Method 2
Using readdir , I loop through the files and stores in an array and then delete only the files instead of the folder.
Which is the best way to do it ? If its not among these then please advice me a better solution.
The rm function of ShellJS will do the trick. It works as a one-liner, and it works cross-platform, and is well tested and documented. It even supports recursive deletes.
Basically, something such as:
const { rm } = require('shelljs');
rm('-rf', '/tmp/*');
(Sample code taken from ShellJS' documentation.)
if FileCopy(ExpandConstant('{tmp}\SPECTRUMJOBS_Data.MDF'),
ExpandConstant('C:\Program Files\Microsoft SQL Server\MSSQL11.LOGISTICS\MSSQL\DATA\SPECTRUMJOBS_Data.MDF'),
False) then
I tried the above one but I am not able to copy because there is no folder named DATA in the location.
so please help me to copy the DATA folder and the file
To force creation of directories you can use (text is from InnoSetup help):
Prototype:
function ForceDirectories(Dir: string): Boolean;
Description:
Creates all the directories along the specified directory
path all at once. If the first directories in the path do exist, but
the latter ones don't, ForceDirectories creates just the ones that
don't exist. Returns True if successful, False otherwise.
InnoSetup documentation is at ishelp
You answered yourself. If there is no folder DATA in folder MSSQL, the folder must be created first.
And... if there is no folder MSSQL in folder MSSQL11.LOGISTICS, that folder must be created first.
And so on...
Now read the above sentences in reverse order, and you're done.
I'm trying to cut a folder. I've tried directoy.move(string source,string dest) & directoryinfo.moveto(dest) but in both case an exception was thrown "Source and destination path must have identical roots. Move will not work across volume".
You cannot move files and folders across different volumes with Directory.Move. You have to create the directory at the destination, recursively copy the files across then, on success, delete the files at the source or, as Tim suggested in the comments below, recursively create the directory structure then move the files across with File.Move.
I want to store file in my_application/PdfReports directory ,i am writing the code to store in the file which is in my_application/grails-app/domain/com/my_company/my_application/reports/ReportExporter.groovy .
So how to get the path my_application/PdfReportsv to store files.
If you are deploying the web-app as a war, then I'm not sure the path my_application/PdfReports makes any sense.
The war file (and exploded war folder) will be the contents of your web-app folder, with related grails stuff inside the WEB-INF folder
Why not use a custom absolute path which you can define in your Config.groovy file
Or, to get the real disk based path for your web-application, you could do something like:
String webAppPath = new File( servletContext.getRealPath( '/index.gsp' ) ).parentFile.absolutePath
from inside a controller