How to delete a folder with files inside [duplicate] - c++

This question already has answers here:
How to delete a folder in C++?
(18 answers)
Closed 9 years ago.
I need to delete a folder, that has files inside it..
I need to permanent delete the files, so they wont come to the receycle bin...
I've looked for many ways, such as rmdir, though it didnt recognized "rmdir" even with includes (I tried to include a lot of stuff that I've found on examples)..
Thanks!
Edit:
I'm using windows 7
I've found this :
system("rmdir D:\\temps /s /q");
which delete the folder correctly, though I want to use a variable that contains the path..
like :
path = "D:\\temps";
delete(path);
or something in this style..
Thanks!

I've used this :
system(path.c_str());
path is a string which holds the path...
in the path I've added rmdir to the beggining...

Related

Is there a way to solve Stata's r(601) while looping the append for imported excel files?

I am trying to append multiple Excel files into a large database by executing the following code:
cls
set more off
clear all
global route = "C:\Users\NICOLE\Desktop\CAR"
cd "$route"
tempfile buildDB
save `buildDB', emptyok
local filenames : dir "$route" files "*.xlsx"
display `filenames'
foreach f of local filenames {
import excel using `"`f'"' ,firstrow allstring clear
gen source = `"`f'"'
append using `buildDB'
save `"`buildDB'"', replace
}
save "C:\Users\NICOLE\Desktop\CAR\DB_EG-RAC.dta" ,replace
Stata manages to append all of the files, but it also displays the following message of error:
file C:\Users\NICOLE.xlsx not found r(601);
And I do not know how to solve it, because it does not let my code run as it should. Thanks!
We have deadlock here. On the face of it the filename in question is not one you write in your code, but could only be part of the result of
local filenames : dir "$route" files "*.xlsx"
But the file named isn't even in the same directory as that named. Moreover, you are adamant that the file doesn't exist and Stata according to your error report can't find it.
The question still remains: how does Stata get asked to open a file that supposedly doesn't exist?
My only guesses are feeble:
Code you are not showing is responsible.
You are running slightly different versions of this script in different places and getting confused. Can you replicate this error that you did get once all over again? Have you searched everywhere remotely possible on the C: drive for this file nicole.xlsx?
It is crucial to realise that we can test nothing here. The problem has not been presented reproducibly.

Edit Single YAML value without updating the formatting of rest of YAML (YAML CPP) [duplicate]

This question already has answers here:
I want to load a YAML file, possibly edit the data, and then dump it again. How can I preserve formatting?
(2 answers)
Closed 2 years ago.
I already have a YAML file. I want to just change a single value inside that YAML file. I found yaml-cpp library being used widely for parsing/editing yaml files from c++ code. Is there a way I can update single value and leave the rest of the file untouched?
I have a YAML file like this already. And I just want to update the parameter 'non_ros_map_width'
# Config file
package_name: "auto_mapping_ros"
csv_filepath: "/csv/sequence"
# Non ROS Map Values
non_ros_map_width : 1000
I tried runnning using yaml-cpp and updated it from the cpp code and I got this:
package_name: !<!> auto_mapping_ros
non_ros_map_height: 1355
csv_filepath: !<!> /csv/sequence
The values seem to be intact. I am not sure about the strings. but my comments have disappeared. Is there a way to just update the single value and not touch the rest of the file.
My code snippet:
YAML::Node node, _baseNode = YAML::LoadFile(auto_mapping_yaml_path); // gets the root node
_baseNode["non_ros_map_width"] = 1355; // edit one of the nodes
std::ofstream fout(auto_mapping_yaml_path);
fout << _baseNode; // dump it back into the file
From the YAML documentation https://yaml.org/spec/1.2/spec.html#id2767100:
Comments are a presentation detail and must not have any effect on the
serialization tree or representation graph.
YAML will remove the comments by design.
A solution would be to edit the file manually: C++ overwriting data in a file at a particular position. But you would also have to parse the file manually.

Move the storage directory outside of the web directory

In opencart version 3 there is a notification:
It is very imporant that you move the storage directory outside of the
web directory (e.g. public_html, www or htdocs)
Screenshot
I tried by clicking on move button in the picture also tried manually but after trying it is giving weird errors.
You can move storage directory outside of the web directory (e.g. public_html, www or htdocs) in three ways
Automatically Moving
Manual Moving (from admin panel)
Manual Moving ( By editing Config files)...
Assuming that you know first and second methods.Here I will explain the third method to you.
Copy your storage directory from system/storage to public_html, www or htdocs.
Change the following file path from both config files i.e. config.php and admin/config.php as shown below.
define('DIR_STORAGE', 'public_html/storage');
Please replace public_html to your desired path.
I hope this answer might help you.
It is very simple to remove / hide this dialog box:
open 'admin/controller/common/dashboard.php' file
search below line
$data['security'] = $this->load->controller('common/security');
and replace it with below line
$data['security'] = '';
That's it :)
Change directory path as decribed abowe--but when You save the config.php use utf8 encoding. I have worked 2 hour on it- did everithing i found on google, but nothing worked. Just this simple thing!
I also ran into this little problem, and the fault was layer 8 (problems between the keyboard and the chair)
I hadn't read the code that I had to change correctly and I was doing it wrong, I'll explain better in case someone runs into the same problem:
capturing the variable to be deleted
I was just replacing the new directory path, not removing the DIR_SYSTEM variable.
you have to delete DIR_SYSTEM and place the new route. that's all.
For this reason it gave me an error and so I came to this post.
It is my first contribution. I hope this helps you.

How can I get the list of files in a folder and all its subfolders using C or C++? [duplicate]

This question already has answers here:
Read file names from a directory
(8 answers)
How can I get the list of files in a directory using C or C++?
(33 answers)
Closed 6 years ago.
I want to get a list of files in a folder, if there are any subfolders inside, I want the list of files within these subfolders, too.
I have read the question
How can I get the list of files in a directory using C or C++?
but it didn't help me solve all the problem.
All I want is a function like this:
vector<string> fileList;
//return the number of files within a folder.
// # dir: the folder directory
// # list: the output list of files
// # filetype: could be multiple similar types
int getFileListFrom(const string & dir, vector<string>:: list,
const string & filetype);
int getFileListFrom(const string & dir, vector<string>:: list,
const vector<string> & filetypes);
I hope this function can be used as follows (hypothetically):
//Example1
fileNum1 = getFileListFrom("C:\\Program Files(x69)\\PornoX", list1, "avi");
//Example2
fileNum2 = getFileListFrom("D:\\myWorkspace\\Documentations\\", list2,
vector<string>("doc","docx","pdf","txt"));
I'm using Windows x86 system, so don't worry about cross-platform issue. Also, if any 3rd-part packages are necessary, please provide download links and documentations.
Any help will be deeply appreciated!

Is Applescript processing new folders that are created in the moment the script runs?

I am working on a script that duplicates folders from an afp share to a local folder and does all kind of things with those folders afterwards. (it deletes the original folders after duplicating)
This code is working fine:
tell application "Finder"
duplicate every folder of folder afpFolder to localFolder with replacing
delete every folder of folder afpFolder
end tell
My problem is that our employees will be adding new folders to afpFolder regulary and quite often. My script is running every 10 seconds (with LaunchAgents) because it needs to process the duplicated data as often as possible.
The question I have is: What happens when the script is duplicating and deleting folders and in the exact same moment somebody adds a new folder to afpFolder?
Does the script only delete what was in afpFolder in the moment it started running or could it be that it would delete one of those newly created folders without duplicating it?
I have also thought about making something with a list. For example:
set folderList to {}
tell application "Finder" to set folderList to every folder of afpFolder
duplicate folderList to localFolder
delete folderList
(this might not work this way)
Can anyone please help me answer the question?
Can I work with the upper code where I just duplicate and delete? Or do I have to worry about the script deleting folders that are created in the moment the script runs, without duplicating them?
If the upper code can cause trouble, can you help me with the list solution?
The first script would delete items that are added between the duplicate and delete commands. But I can't think of any case where the second approach would not work:
tell application "Finder"
set l to items of ((POSIX file "/private/tmp/test") as alias)
duplicate l to desktop
delete l
end tell
You could also try using mv or rsync:
do shell script "mv /path/to/afp_folder/* /path/to/local_folder/"
do shell script "rsync -a /path/to/afp_folder/ /path/to/local_folder/
rm -r /path/to/afp_folder/*"
The code from your answer #John Alarik is inefficient and I think in some spots it won't even work. Please don't take that as a criticism because I can see you're trying hard to find a solution which is the right way to go about getting help. So I thought I'd help with your code.
First you seem to be doing many unnecessary conversions of strings, alias's, and file specifications. In addition some of them are incorrect in the context you are using them and will probably cause errors. Your repeat statement in overly complicated too.
Try this code. It works in the same manner as you want but is much cleaner and shouldn't have any errors. I hope it helps. Good luck.
set afpFolder to "examplepath:path:folder:" as alias
set localFolder to "examplepath:path:folder:" as alias
tell application "Finder"
set folderList to folders of afpFolder
repeat with aFolder in folderList
duplicate aFolder to localFolder with replacing
delete aFolder
end repeat
end tell
Don't make it more complicated than it needs to be.
Both Duplicate and Delete can accept a list as a direct parameter. There is no need for any repeat loops. Please note that this is the same format that Lauri suggested, just formatted with the OP's example. Give her the upvote.
set afpFolder to "examplepath:path:folder:" as alias
set localFolder to "examplepath:path:folder:" as alias
tell application "Finder"
set folderList to folders of afpFolder
duplicate folderList to localFolder
delete folderList
end tell
Update: See #regulus6633's post about this code!
Thanks for all the help. In the meantime I could solve my problem even without your answers due to a good code snippet I found for making and processing a list.
This is the final solution, which works fine even if you copy a new folder to afpFolder while the script is running.
tell application "Finder"
set afpFolder to "examplepath:path:folder:" as alias
set localFolder to "examplepath:path:folder:" as string
set folderList to every folder of folder afpFolder
set i to 1
repeat the count of folderList times
set afpUniqueFolder to (item i of folderList) as string
duplicate afpUniqueFolder to localFolder
delete afpUniqueFolder
set i to i + 1
end repeat
end tell
I know that there is also a command called move instead of duplicate and delete.
We had some strange issues with move before, so since then I stick to duplicate and delete.
Thanks to all! This website is very helpful!